From fef23da095b283620b86ef6d072eb0a2e60f3c79 Mon Sep 17 00:00:00 2001 From: h00600710 Date: Mon, 2 Sep 2024 16:24:48 +0800 Subject: [PATCH] delete unuse code of MIRStructType [coverage]delete MIRStructType part1 Change-Id: I4b44ca36ed009f210d81c9cc89358c437790a1f4 [coverage]delete MIRStructType part2 Change-Id: I0182f50074edf221fafe29e8ba71c224b3e01c8e [coverage]delete MIRStructType part3 Change-Id: I0e1206169ed53f5ce37cd42cd9541760a7cdfcec [coverage]delete MIRStructType part4 Issue: #IAOKQI Change-Id: If7db8c11e6d14e51e9123ec7e4184eb96d10469a Signed-off-by: h00600710 --- .../maple/maple_be/include/be/becommon.h | 12 - .../codegen/maple/maple_be/include/be/lower.h | 14 +- .../maple_be/include/cg/aarch64/aarch64_cg.h | 2 - .../include/cg/aarch64/aarch64_cgfunc.h | 1 - .../maple/maple_be/include/cg/call_conv.h | 12 +- .../codegen/maple/maple_be/include/cg/cg.h | 3 - .../maple/maple_be/include/cg/cg_option.h | 11 - .../maple/maple_be/include/cg/cg_options.h | 1 - .../maple/maple_be/include/cg/cgfunc.h | 11 - .../codegen/maple/maple_be/include/cg/emit.h | 2 - .../maple/maple_be/include/cg/x86_64/x64_cg.h | 3 - .../maple_be/include/cg/x86_64/x64_emitter.h | 3 - .../maple_be/include/litecg/lmir_builder.h | 76 - .../maple/maple_be/src/be/becommon.cpp | 245 +-- .../codegen/maple/maple_be/src/be/lower.cpp | 532 +------ .../maple_be/src/cg/aarch64/aarch64_cg.cpp | 15 - .../src/cg/aarch64/aarch64_cgfunc.cpp | 79 +- .../src/cg/aarch64/aarch64_memlayout.cpp | 21 - .../maple/maple_be/src/cg/cg_option.cpp | 4 - .../maple/maple_be/src/cg/cg_options.cpp | 6 - .../maple/maple_be/src/cg/cg_phasemanager.cpp | 3 - .../codegen/maple/maple_be/src/cg/cgfunc.cpp | 10 - .../codegen/maple/maple_be/src/cg/emit.cpp | 197 +-- .../codegen/maple/maple_be/src/cg/isel.cpp | 6 - .../maple_be/src/cg/x86_64/x64_MPIsel.cpp | 57 +- .../maple/maple_be/src/cg/x86_64/x64_cg.cpp | 3 - .../maple_be/src/cg/x86_64/x64_emitter.cpp | 120 +- .../maple_be/src/cg/x86_64/x64_memlayout.cpp | 20 - .../maple_be/src/litecg/lmir_builder.cpp | 39 - .../maple/maple_ir/include/global_tables.h | 26 - .../maple/maple_ir/include/intrinsics.h | 1 - .../maple_ir/include/ir_safe_cast_traits.def | 9 - .../maple/maple_ir/include/mir_builder.h | 22 - .../maple/maple_ir/include/mir_function.h | 20 - .../maple/maple_ir/include/mir_module.h | 5 - .../maple/maple_ir/include/mir_nodes.h | 7 - .../maple/maple_ir/include/mir_symbol.h | 25 +- .../codegen/maple/maple_ir/include/mir_type.h | 840 ---------- .../maple/maple_ir/src/global_tables.cpp | 48 - .../codegen/maple/maple_ir/src/intrinsics.cpp | 46 - .../maple/maple_ir/src/mir_builder.cpp | 206 --- .../maple/maple_ir/src/mir_function.cpp | 42 - .../codegen/maple/maple_ir/src/mir_lower.cpp | 10 - .../codegen/maple/maple_ir/src/mir_module.cpp | 98 -- .../codegen/maple/maple_ir/src/mir_nodes.cpp | 89 +- .../codegen/maple/maple_ir/src/mir_type.cpp | 1407 +---------------- .../maple/maple_me/include/orig_symbol.h | 15 - .../maple/mpl2mpl/src/constantfold.cpp | 18 - 48 files changed, 62 insertions(+), 4380 deletions(-) diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/be/becommon.h b/ecmascript/compiler/codegen/maple/maple_be/include/be/becommon.h index cbf2c3622c..57f4713d70 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/be/becommon.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/be/becommon.h @@ -43,10 +43,6 @@ public: void ComputeTypeSizesAligns(MIRType &type, uint8 align = 0); - std::pair GetFieldOffset(MIRStructType &structType, FieldID fieldID); - - bool IsRefField(MIRStructType &structType, FieldID fieldID) const; - void AddNewTypeAfterBecommon(uint32 oldTypeTableSize, uint32 newTypeTableSize); bool HasFuncReturnType(MIRFunction &func) const @@ -86,13 +82,6 @@ public: uint32 GetFieldIdxIncrement(const MIRType &ty) const { - if (ty.GetKind() == kTypeClass) { - /* number of fields + 2 */ - return static_cast(ty).GetFieldsSize() + 2; - } else if (ty.GetKind() == kTypeStruct) { - /* number of fields + 1 */ - return static_cast(ty).GetFieldsSize() + 1; - } return 1; } @@ -182,7 +171,6 @@ public: private: bool TyIsInSizeAlignTable(const MIRType &) const; void AddAndComputeSizeAlign(MIRType &); - void ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx); MIRModule &mirModule; MapleVector typeSizeTable; /* index is TyIdx */ diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/be/lower.h b/ecmascript/compiler/codegen/maple/maple_be/include/be/lower.h index c8d0c5fd32..cd0e60d736 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/be/lower.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/be/lower.h @@ -92,7 +92,8 @@ public: if (iread.GetPrimType() == PTY_u1) { iread.SetPrimType(PTY_u8); } - return (iread.GetFieldID() == 0 ? &iread : LowerIreadBitfield(iread)); + CHECK_FATAL(iread.GetFieldID() == 0, "fieldID must be 0"); + return &iread; } BaseNode *LowerCastExpr(BaseNode &expr); @@ -107,8 +108,6 @@ public: void LowerRegassign(RegassignNode ®Assign, BlockNode &block); - StmtNode *LowerIntrinsicopDassign(const DassignNode &dassign, IntrinsicopNode &intrinsic, BlockNode &block); - BaseNode *LowerAddrof(AddrofNode &addrof) const { return &addrof; @@ -126,11 +125,6 @@ public: * To be able to handle them in a unified manner, we lower intrinsiccall to Intrinsicsicop. */ BlockNode *LowerIntrinsiccallToIntrinsicop(StmtNode &stmt); - bool LowerStructReturnInRegs(BlockNode &newBlk, StmtNode &stmt, const MIRSymbol &retSym); - void LowerStructReturnInGpRegs(BlockNode &newBlk, const StmtNode &stmt, const MIRSymbol &symbol); - void LowerStructReturnInFpRegs(BlockNode &newBlk, const StmtNode &stmt, const MIRSymbol &symbol, PrimType primType, - size_t elemNum); - bool LowerStructReturn(BlockNode &newBlk, StmtNode &stmt, bool &lvar); void LowerStmt(StmtNode &stmt, BlockNode &block); @@ -156,10 +150,6 @@ public: BaseNode *baseAddr, BaseNode *rhs, BlockNode *block); BaseNode *ReadBitField(const std::pair &byteBitOffsets, const MIRBitFieldType *fieldType, BaseNode *baseAddr); - BaseNode *LowerDreadBitfield(DreadNode &dread); - BaseNode *LowerIreadBitfield(IreadNode &iread); - StmtNode *LowerDassignBitfield(DassignNode &dassign, BlockNode &block); - StmtNode *LowerIassignBitfield(IassignNode &iassign, BlockNode &block); void LowerAsmStmt(AsmNode *asmNode, BlockNode *blk); 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 3f4cfc1156..33b45f2005 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 @@ -60,8 +60,6 @@ public: return cyclePatternMap; } - void GenerateObjectMaps(BECommon &beCommon) override; - bool IsExclusiveFunc(MIRFunction &) override; void EmitGCTIBLabel(GCTIBKey *key, const std::string &gcTIBName, std::vector &bitmapWords, uint32 rcHeader); 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 1daf4036a0..3c0d795698 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 @@ -89,7 +89,6 @@ public: void MergeReturn() override; void SelectDassign(DassignNode &stmt, Operand &opnd0) override; void SelectRegassign(RegassignNode &stmt, Operand &opnd0) override; - MemOperand *GenFormalMemOpndWithSymbol(const MIRSymbol &sym, int64 offset); void SelectIassign(IassignNode &stmt) override; void SelectReturn(Operand *opnd0) override; bool DoCallerEnsureValidParm(RegOperand &destOpnd, RegOperand &srcOpnd, PrimType formalPType); diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/call_conv.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/call_conv.h index 115bcc1d76..b0da5b09d0 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/call_conv.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/call_conv.h @@ -112,8 +112,7 @@ struct CCLocInfo { class LmbcFormalParamInfo { public: LmbcFormalParamInfo(PrimType pType, uint32 ofst, uint32 sz) - : type(nullptr), - primType(pType), + : primType(pType), offset(ofst), onStackOffset(0), size(sz), @@ -130,14 +129,6 @@ public: ~LmbcFormalParamInfo() = default; - MIRStructType *GetType() - { - return type; - } - void SetType(MIRStructType *ty) - { - type = ty; - } PrimType GetPrimType() const { return primType; @@ -240,7 +231,6 @@ public: } private: - MIRStructType *type; PrimType primType; uint32 offset; uint32 onStackOffset; /* stack location if isOnStack */ 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 4b8b44d92c..86be945432 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cg.h @@ -212,9 +212,6 @@ public: virtual bool IsExclusiveFunc(MIRFunction &mirFunc) = 0; - /* NOTE: Consider making be_common a field of CG. */ - virtual void GenerateObjectMaps(BECommon &beCommon) = 0; - /* Used for GCTIB pattern merging */ virtual std::string FindGCTIBPatternName(const std::string &name) const = 0; 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 09a275c898..1ef9bab77f 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 @@ -292,16 +292,6 @@ public: asmEmitterEnable = flag; } - bool IsGenerateObjectMap() const - { - return generateObjectMap; - } - - void SetGenerateObjectMap(bool flag) - { - generateObjectMap = flag; - } - void SetParserOption(uint32 option) { parserOption |= option; @@ -888,7 +878,6 @@ private: bool runCGFlag = true; bool asmEmitterEnable = false; - bool generateObjectMap = true; uint32 parserOption = 0; int32 optimizeLevel = 0; 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 65ec713b3e..526cbeab00 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 @@ -30,7 +30,6 @@ extern maplecl::Option cg; extern maplecl::Option generalRegOnly; extern maplecl::Option lazyBinding; extern maplecl::Option hotFix; -extern maplecl::Option objmap; extern maplecl::Option yieldpoint; extern maplecl::Option localRc; extern maplecl::Option debug; 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 ab80cbf37f..10195f01da 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/cgfunc.h @@ -25,7 +25,6 @@ #include "cfi.h" #include "cg_cfg.h" #include "cg_irbuilder.h" -#include "call_conv.h" /* MapleIR headers. */ #include "mir_function.h" @@ -1175,16 +1174,6 @@ protected: return offset; } - /* See if the symbol is a structure parameter that requires a copy. */ - bool IsParamStructCopy(const MIRSymbol &symbol) const - { - auto *mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(symbol.GetTyIdx()); - if (symbol.GetStorageClass() == kScFormal && IsParamStructCopyToMemory(*mirType)) { - return true; - } - return false; - } - PrimType GetPrimTypeFromSize(uint32 byteSize, PrimType defaultType) const { constexpr uint32 oneByte = 1; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/emit.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/emit.h index 1408d2e3f0..64f12d52d7 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/emit.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/emit.h @@ -223,8 +223,6 @@ public: void EmitMethodDeclaringClass(const MIRSymbol &mirSymbol, const std::string §ionName); void MarkVtabOrItabEndFlag(const std::vector &mirSymbolVec); void EmitArrayConstant(MIRConst &mirConst); - void EmitStructConstant(MIRConst &mirConst); - void EmitStructConstant(MIRConst &mirConst, uint32 &subStructFieldCounts); void EmitLocalVariable(const CGFunc &cgFunc); void EmitUninitializedSymbolsWithPrefixSection(const MIRSymbol &symbol, const std::string §ionName); void EmitGlobalVariable(); 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 25677606da..016d50fb98 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 @@ -84,9 +84,6 @@ public: bool IsExclusiveFunc(MIRFunction &mirFunc) override; - /* NOTE: Consider making be_common a field of CG. */ - void GenerateObjectMaps(BECommon &beCommon) override; - void DoNothing() { (void)ehExclusiveNameVec; diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_emitter.h b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_emitter.h index bad22df90b..f66f2fbeda 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_emitter.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/cg/x86_64/x64_emitter.h @@ -46,9 +46,6 @@ public: uint64 GetSymbolSize(maple::TyIdx typeIndex); void EmitLocalVariable(maplebe::CGFunc &cgFunc); void EmitGlobalVariable(maplebe::CG &cg); - uint64 EmitStructure(maple::MIRConst &mirConst, maplebe::CG &cg, bool belongsToDataSec = true); - uint64 EmitStructure(maple::MIRConst &mirConst, maplebe::CG &cg, uint32 &subStructFieldCounts, - bool belongsToDataSec = true); uint64 EmitVector(maple::MIRConst &mirConst, bool belongsToDataSec = true); uint64 EmitArray(maple::MIRConst &mirConst, maplebe::CG &cg, bool belongsToDataSec = true); void EmitAddrofElement(MIRConst &mirConst, bool belongsToDataSec); diff --git a/ecmascript/compiler/codegen/maple/maple_be/include/litecg/lmir_builder.h b/ecmascript/compiler/codegen/maple/maple_be/include/litecg/lmir_builder.h index 2e0f50dfdb..5c1ab9ec38 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/include/litecg/lmir_builder.h +++ b/ecmascript/compiler/codegen/maple/maple_be/include/litecg/lmir_builder.h @@ -48,7 +48,6 @@ class MIRBuilder; // currently we just delegate MIRBuilder class MIRModule; class MIRFunction; class MIRType; -class MIRStructType; class MIRArrayType; class MIRFuncType; class MIRConst; @@ -70,7 +69,6 @@ using Function = MIRFunction; // Note: Type is base class of all other Types using Type = MIRType; // base class of all Types -using StructType = MIRStructType; // |__ StructType using ArrayType = MIRArrayType; using Const = MIRConst; using StructConst = MIRAggConst; @@ -270,14 +268,6 @@ public: bool IsHeapPointerType(Type *mirType) const; - /* using StructTypeBuilder interface for StructType creation - auto structType = CreateStructType("mystruct") - .Field("field1", i32Type) - .Field("field2", i64Type) - .Done(); - */ - Type *GetStructType(const String &name); // query for existing struct type - // for function pointer Type *CreateFuncType(std::vector params, Type *retType, bool isVarg); @@ -331,14 +321,6 @@ public: Const &CreateDoubleConst(double val); Const *GetConstFromExpr(const Expr &expr); - // In MIR, the const for struct & array are the same. But we separate it here. - /* using StructConstBuilder interface for StructConst creation: - auto structConst = CreateStructConst(structType) - .Field(1, CreateIntConst(i32Type, 0)) - .Filed(2, CreateIntConst(i64Type, 0)) - .Done(); - */ - /* using ArrayConstBuilder interface for ArrayConst creation: Note: the elements should be added consequentially, and match the dim size. auto arrayConst = CreateArrayConst(arrayType) @@ -422,7 +404,6 @@ public: return Dread(*var); } - Expr DreadWithField(Var &var, FieldId id); Expr IntrinsicOp(IntrinsicId id, Type *type, Args &args_); Expr Iread(Type *type, Expr addr, Type *baseType, FieldId fieldId = 0); PregIdx CreatePreg(Type *mtype); @@ -502,61 +483,6 @@ public: return SwitchBuilder(*this, type, cond, defaultBB); } - class StructTypeBuilder { - public: - StructTypeBuilder(LMIRBuilder &builder_, const String &name_) : builder(builder_), name(name_) {} - - StructTypeBuilder &Field(std::string_view fieldName, Type *fieldType) - { - // field type attribute? - fields.push_back(std::make_pair(fieldName, fieldType)); - return *this; - } - - Type *Done() - { - return builder.CreateStructTypeInternal(name, fields); - } - - private: - LMIRBuilder &builder; - const String &name; - std::vector> fields; - }; - - StructTypeBuilder CreateStructType(const String &name) - { - return StructTypeBuilder(*this, name); - } - - class StructConstBuilder { - public: - StructConstBuilder(LMIRBuilder &builder_, StructType *type_) : builder(builder_) - { - structConst = &builder_.CreateStructConstInternal(type_); - } - - StructConstBuilder &Field(FieldId fieldId, Const &field) - { - builder.AddConstItemInternal(*structConst, fieldId, field); - return *this; - } - - StructConst &Done() - { - return *structConst; - } - - private: - LMIRBuilder &builder; - StructConst *structConst; - }; - - StructConstBuilder CreateStructConst(StructType *type) - { - return StructConstBuilder(*this, type); - } - class ArrayConstBuilder { public: ArrayConstBuilder(LMIRBuilder &builder_, ArrayType *type_) : builder(builder_) @@ -699,8 +625,6 @@ public: private: Stmt &CreateSwitchInternal(Type *type, Expr cond, BB &defaultBB, std::vector> &cases); - Type *CreateStructTypeInternal(const String &name, std::vector> &fields); - StructConst &CreateStructConstInternal(StructType *type); void AddConstItemInternal(StructConst &structConst, FieldId fieldId, Const &field); void AddConstItemInternal(ArrayConst &structConst, Const &element); ArrayConst &CreateArrayConstInternal(ArrayType *type); 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 121a6d989e..e10a6bedb7 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/be/becommon.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/be/becommon.cpp @@ -53,96 +53,6 @@ void BECommon::AddNewTypeAfterBecommon(uint32 oldTypeTableSize, uint32 newTypeTa } } -void BECommon::ComputeStructTypeSizesAligns(MIRType &ty, const TyIdx &tyIdx) -{ - auto &structType = static_cast(ty); - const FieldVector &fields = structType.GetFields(); - uint64 allocedSize = 0; - uint64 allocedSizeInBits = 0; - SetStructFieldCount(structType.GetTypeIndex(), fields.size()); - if (fields.size() == 0) { - if (structType.IsCPlusPlus()) { - SetTypeSize(tyIdx.GetIdx(), 1); /* empty struct in C++ has size 1 */ - SetTypeAlign(tyIdx.GetIdx(), 1); - } else { - SetTypeSize(tyIdx.GetIdx(), 0); - SetTypeAlign(tyIdx.GetIdx(), k8ByteSize); - } - return; - } - auto structAttr = structType.GetTypeAttrs(); - auto structPack = static_cast(structAttr.GetPack()); - for (uint32 j = 0; j < fields.size(); ++j) { - TyIdx fieldTyIdx = fields[j].second.first; - auto fieldAttr = fields[j].second.second; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - uint32 fieldTypeSize = GetTypeSize(fieldTyIdx); - if (fieldTypeSize == 0) { - ComputeTypeSizesAligns(*fieldType); - fieldTypeSize = GetTypeSize(fieldTyIdx); - } - uint64 fieldSizeBits = fieldTypeSize * kBitsPerByte; - auto attrAlign = static_cast(fieldAttr.GetAlign()); - auto originAlign = std::max(attrAlign, GetTypeAlign(fieldTyIdx)); - uint8 fieldAlign = fieldAttr.IsPacked() ? 1 : std::min(originAlign, structPack); - uint64 fieldAlignBits = fieldAlign * kBitsPerByte; - CHECK_FATAL(fieldAlign != 0, "expect fieldAlign not equal 0"); - MIRStructType *subStructType = fieldType->EmbeddedStructType(); - if (subStructType != nullptr) { - AppendStructFieldCount(structType.GetTypeIndex(), GetStructFieldCount(subStructType->GetTypeIndex())); - } - if (structType.GetKind() != kTypeUnion) { - if (fieldType->GetKind() == kTypeBitField) { - uint32 fieldSize = static_cast(fieldType)->GetFieldSize(); - /* is this field is crossing the align boundary of its base type? */ - if ((!structAttr.IsPacked() && - ((allocedSizeInBits / fieldSizeBits) != ((allocedSizeInBits + fieldSize - 1u) / fieldSizeBits))) || - fieldSize == 0) { - allocedSizeInBits = RoundUp(allocedSizeInBits, fieldSizeBits); - } - /* allocate the bitfield */ - allocedSizeInBits += fieldSize; - allocedSize = std::max(allocedSize, RoundUp(allocedSizeInBits, fieldAlignBits) / kBitsPerByte); - } else { - bool leftoverbits = false; - - if (allocedSizeInBits == allocedSize * kBitsPerByte) { - allocedSize = RoundUp(allocedSize, fieldAlign); - } else { - /* still some leftover bits on allocated words, we calculate things based on bits then. */ - if (allocedSizeInBits / fieldAlignBits != - (allocedSizeInBits + fieldSizeBits - 1) / fieldAlignBits) { - /* the field is crossing the align boundary of its base type */ - allocedSizeInBits = RoundUp(allocedSizeInBits, fieldAlignBits); - } - leftoverbits = true; - } - if (leftoverbits) { - allocedSizeInBits += fieldSizeBits; - allocedSize = std::max(allocedSize, RoundUp(allocedSizeInBits, fieldAlignBits) / kBitsPerByte); - } else { - /* pad alloced_size according to the field alignment */ - allocedSize = RoundUp(allocedSize, fieldAlign); - allocedSize += fieldTypeSize; - allocedSizeInBits = allocedSize * kBitsPerByte; - } - } - } else { /* for unions, bitfields are treated as non-bitfields */ - allocedSize = std::max(allocedSize, static_cast(fieldTypeSize)); - } - SetTypeAlign(tyIdx, std::max(GetTypeAlign(tyIdx), fieldAlign)); - /* C99 - * Last struct element of a struct with more than one member - * is a flexible array if it is an array of size 0. - */ - if ((j != 0) && ((j + 1) == fields.size()) && (fieldType->GetKind() == kTypeArray) && - (GetTypeSize(fieldTyIdx.GetIdx()) == 0)) { - SetHasFlexibleArray(tyIdx.GetIdx(), true); - } - } - SetTypeSize(tyIdx, RoundUp(allocedSize, GetTypeAlign(tyIdx.GetIdx()))); -} - void BECommon::ComputeTypeSizesAligns(MIRType &ty, uint8 align) { TyIdx tyIdx = ty.GetTypeIndex(); @@ -162,16 +72,10 @@ void BECommon::ComputeTypeSizesAligns(MIRType &ty, uint8 align) SetTypeSize(tyIdx, GetPrimTypeSize(ty.GetPrimType())); SetTypeAlign(tyIdx, GetTypeSize(tyIdx)); break; - case kTypeUnion: - case kTypeStruct: { - ComputeStructTypeSizesAligns(ty, tyIdx); - break; - } case kTypeArray: case kTypeFArray: case kTypeJArray: - case kTypeInterface: - case kTypeClass: { /* cannot have union or bitfields */ + case kTypeInterface: { /* cannot have union or bitfields */ CHECK_FATAL(false, "unsupported type"); break; } @@ -185,138 +89,6 @@ void BECommon::ComputeTypeSizesAligns(MIRType &ty, uint8 align) SetTypeAlign(tyIdx, std::max(GetTypeAlign(tyIdx), align)); } -bool BECommon::IsRefField(MIRStructType &structType, FieldID fieldID) const -{ - return false; -} - -/* - * compute the offset of the field given by fieldID within the structure type - * structy; it returns the answer in the pair (byteoffset, bitoffset) such that - * if it is a bitfield, byteoffset gives the offset of the container for - * extracting the bitfield and bitoffset is with respect to the container - */ -std::pair BECommon::GetFieldOffset(MIRStructType &structType, FieldID fieldID) -{ - CHECK_FATAL(fieldID <= GetStructFieldCount(structType.GetTypeIndex()), "GetFieldOFfset: fieldID too large"); - uint64 allocedSize = 0; - uint64 allocedSizeInBits = 0; - FieldID curFieldID = 1; - if (fieldID == 0) { - return std::pair(0, 0); - } - DEBUG_ASSERT(structType.GetKind() != kTypeClass, "unsupported kTypeClass type"); - - /* process the struct fields */ - FieldVector fields = structType.GetFields(); - auto structPack = static_cast(structType.GetTypeAttrs().GetPack()); - for (uint32 j = 0; j < fields.size(); ++j) { - TyIdx fieldTyIdx = fields[j].second.first; - auto fieldAttr = fields[j].second.second; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - uint32 fieldTypeSize = GetTypeSize(fieldTyIdx); - uint64 fieldSizeBits = fieldTypeSize * kBitsPerByte; - auto originAlign = GetTypeAlign(fieldTyIdx); - auto fieldAlign = fieldAttr.IsPacked() ? 1 : std::min(originAlign, structPack); - uint64 fieldAlignBits = static_cast(fieldAlign * kBitsPerByte); - CHECK_FATAL(fieldAlign != 0, "fieldAlign should not equal 0"); - if (structType.GetKind() != kTypeUnion) { - if (fieldType->GetKind() == kTypeBitField) { - uint32 fieldSize = static_cast(fieldType)->GetFieldSize(); - /* - * Is this field is crossing the align boundary of its base type? Or, - * is field a zero-with bit field? - * Refer to C99 standard (§6.7.2.1) : - * > As a special case, a bit-field structure member with a width of 0 indicates that no further - * > bit-field is to be packed into the unit in which the previous bit-field, if any, was placed. - * - * We know that A zero-width bit field can cause the next field to be aligned on the next container - * boundary where the container is the same size as the underlying type of the bit field. - */ - CHECK_FATAL(allocedSizeInBits <= UINT64_MAX - fieldSize, "must not be zero"); - DEBUG_ASSERT(allocedSizeInBits + fieldSize >= 1, "allocedSizeInBits + fieldSize - 1u must be unsigned"); - if ((!structType.GetTypeAttrs().IsPacked() && - ((allocedSizeInBits / fieldSizeBits) != ((allocedSizeInBits + fieldSize - 1u) / fieldSizeBits))) || - fieldSize == 0) { - /* - * the field is crossing the align boundary of its base type; - * align alloced_size_in_bits to fieldAlign - */ - allocedSizeInBits = RoundUp(allocedSizeInBits, fieldSizeBits); - } - /* allocate the bitfield */ - if (curFieldID == fieldID) { - return std::pair((allocedSizeInBits / fieldAlignBits) * fieldAlign, - allocedSizeInBits % fieldAlignBits); - } else { - ++curFieldID; - } - allocedSizeInBits += fieldSize; - allocedSize = std::max(allocedSize, RoundUp(allocedSizeInBits, fieldAlignBits) / kBitsPerByte); - } else { - bool leftOverBits = false; - uint64 offset = 0; - - if (allocedSizeInBits == allocedSize * k8BitSize) { - allocedSize = RoundUp(allocedSize, fieldAlign); - offset = allocedSize; - } else { - /* still some leftover bits on allocated words, we calculate things based on bits then. */ - if (allocedSizeInBits / fieldAlignBits != - (allocedSizeInBits + fieldSizeBits - k1BitSize) / fieldAlignBits) { - /* the field is crossing the align boundary of its base type */ - allocedSizeInBits = RoundUp(allocedSizeInBits, fieldAlignBits); - } - allocedSize = RoundUp(allocedSize, fieldAlign); - offset = static_cast((allocedSizeInBits / fieldAlignBits) * fieldAlign); - leftOverBits = true; - } - - if (curFieldID == fieldID) { - return std::pair(offset, 0); - } else { - MIRStructType *subStructType = fieldType->EmbeddedStructType(); - if (subStructType == nullptr) { - ++curFieldID; - } else { - if ((curFieldID + GetStructFieldCount(subStructType->GetTypeIndex())) < fieldID) { - curFieldID += GetStructFieldCount(subStructType->GetTypeIndex()) + 1; - } else { - std::pair result = GetFieldOffset(*subStructType, fieldID - curFieldID); - return std::pair(result.first + allocedSize, result.second); - } - } - } - - if (leftOverBits) { - allocedSizeInBits += fieldSizeBits; - allocedSize = std::max(allocedSize, RoundUp(allocedSizeInBits, fieldAlignBits) / kBitsPerByte); - } else { - allocedSize += fieldTypeSize; - allocedSizeInBits = allocedSize * kBitsPerByte; - } - } - } else { /* for unions, bitfields are treated as non-bitfields */ - if (curFieldID == fieldID) { - return std::pair(0, 0); - } else { - MIRStructType *subStructType = fieldType->EmbeddedStructType(); - if (subStructType == nullptr) { - curFieldID++; - } else { - if ((curFieldID + GetStructFieldCount(subStructType->GetTypeIndex())) < fieldID) { - curFieldID += GetStructFieldCount(subStructType->GetTypeIndex()) + 1; - } else { - return GetFieldOffset(*subStructType, fieldID - curFieldID); - } - } - } - } - } - CHECK_FATAL(false, "GetFieldOffset() fails to find field"); - return std::pair(0, 0); -} - bool BECommon::TyIsInSizeAlignTable(const MIRType &ty) const { if (typeSizeTable.size() != typeAlignTable.size()) { @@ -385,19 +157,8 @@ BaseNode *BECommon::GetAddressOfNode(const BaseNode &node) } case OP_iread: { const IreadNode &iNode = static_cast(node); - if (iNode.GetFieldID() == 0) { - return iNode.Opnd(0); - } - - uint32 index = static_cast(GlobalTables::GetTypeTable().GetTypeTable().at(iNode.GetTyIdx())) - ->GetPointedTyIdx(); - MIRType *pointedType = GlobalTables::GetTypeTable().GetTypeTable().at(index); - std::pair byteBitOffset = - GetFieldOffset(static_cast(*pointedType), iNode.GetFieldID()); - return mirModule.GetMIRBuilder()->CreateExprBinary( - OP_add, *GlobalTables::GetTypeTable().GetPrimType(GetAddressPrimType()), - static_cast(iNode.Opnd(0)), - mirModule.GetMIRBuilder()->CreateIntConst(byteBitOffset.first, PTY_u32)); + CHECK_FATAL(iNode.GetFieldID() == 0, "fieldId must be 0"); + return iNode.Opnd(0); } default: return nullptr; 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 12e13742a1..2686cd8466 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/be/lower.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/be/lower.cpp @@ -36,30 +36,8 @@ using namespace maple; BaseNode *CGLowerer::LowerIaddrof(const IreadNode &iaddrof) { - if (iaddrof.GetFieldID() == 0) { - return iaddrof.Opnd(0); - } - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(iaddrof.GetTyIdx()); - MIRPtrType *pointerTy = static_cast(type); - CHECK_FATAL(pointerTy != nullptr, "LowerIaddrof: expect a pointer type at iaddrof node"); - MIRStructType *structTy = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointerTy->GetPointedTyIdx())); - CHECK_FATAL(structTy != nullptr, "LowerIaddrof: non-zero fieldID for non-structure"); - int32 offset = beCommon.GetFieldOffset(*structTy, iaddrof.GetFieldID()).first; - if (offset == 0) { - return iaddrof.Opnd(0); - } - uint32 loweredPtrType = static_cast(GetLoweredPtrType()); - MIRIntConst *offsetConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst( - offset, *GlobalTables::GetTypeTable().GetTypeTable().at(loweredPtrType)); - BaseNode *offsetNode = mirModule.CurFuncCodeMemPool()->New(offsetConst); - offsetNode->SetPrimType(GetLoweredPtrType()); - - BinaryNode *addNode = mirModule.CurFuncCodeMemPool()->New(OP_add); - addNode->SetPrimType(GetLoweredPtrType()); - addNode->SetBOpnd(iaddrof.Opnd(0), 0); - addNode->SetBOpnd(offsetNode, 1); - return addNode; + CHECK_FATAL(iaddrof.GetFieldID() == 0, "fieldID must be 0"); + return iaddrof.Opnd(0); } StmtNode *CGLowerer::WriteBitField(const std::pair &byteBitOffsets, const MIRBitFieldType *fieldType, @@ -136,44 +114,6 @@ BaseNode *CGLowerer::ReadBitField(const std::pair &byteBitOffsets, return result; } -BaseNode *CGLowerer::LowerDreadBitfield(DreadNode &dread) -{ - DEBUG_ASSERT(mirModule.CurFunction() != nullptr, "CurFunction should not be nullptr"); - auto *symbol = mirModule.CurFunction()->GetLocalOrGlobalSymbol(dread.GetStIdx()); - DEBUG_ASSERT(symbol != nullptr, "symbol should not be nullptr"); - auto *structTy = static_cast(symbol->GetType()); - auto fTyIdx = structTy->GetFieldTyIdx(dread.GetFieldID()); - auto *fType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(fTyIdx)); - if (fType->GetKind() != kTypeBitField) { - return &dread; - } - auto *builder = mirModule.GetMIRBuilder(); - auto *baseAddr = builder->CreateExprAddrof(0, dread.GetStIdx()); - auto byteBitOffsets = beCommon.GetFieldOffset(*structTy, dread.GetFieldID()); - return ReadBitField(byteBitOffsets, static_cast(fType), baseAddr); -} - -BaseNode *CGLowerer::LowerIreadBitfield(IreadNode &iread) -{ - uint32 index = iread.GetTyIdx(); - MIRPtrType *pointerTy = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(index)); - MIRType *pointedTy = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointerTy->GetPointedTyIdx()); - /* Here pointed type can be Struct or JArray */ - MIRStructType *structTy = nullptr; - if (pointedTy->GetKind() != kTypeJArray) { - structTy = static_cast(pointedTy); - } else { - structTy = static_cast(pointedTy)->GetParentType(); - } - TyIdx fTyIdx = structTy->GetFieldTyIdx(iread.GetFieldID()); - MIRType *fType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(fTyIdx)); - if (fType->GetKind() != kTypeBitField) { - return &iread; - } - auto byteBitOffsets = beCommon.GetFieldOffset(*structTy, iread.GetFieldID()); - return ReadBitField(byteBitOffsets, static_cast(fType), iread.Opnd(0)); -} - // input node must be cvt, retype, zext or sext BaseNode *CGLowerer::LowerCastExpr(BaseNode &expr) { @@ -242,67 +182,12 @@ BlockNode *CGLowerer::LowerReturn(NaryStmtNode &retNode) return blk; } -StmtNode *CGLowerer::LowerDassignBitfield(DassignNode &dassign, BlockNode &newBlk) -{ - dassign.SetRHS(LowerExpr(dassign, *dassign.GetRHS(), newBlk)); - DEBUG_ASSERT(mirModule.CurFunction() != nullptr, "CurFunction should not be nullptr"); - MIRSymbol *symbol = mirModule.CurFunction()->GetLocalOrGlobalSymbol(dassign.GetStIdx()); - MIRStructType *structTy = static_cast(symbol->GetType()); - CHECK_FATAL(structTy != nullptr, "LowerDassignBitfield: non-zero fieldID for non-structure"); - TyIdx fTyIdx = structTy->GetFieldTyIdx(dassign.GetFieldID()); - CHECK_FATAL(fTyIdx != 0u, "LowerDassignBitField: field id out of range for the structure"); - MIRType *fType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(fTyIdx)); - if (fType->GetKind() != kTypeBitField) { - return &dassign; - } - auto *builder = mirModule.GetMIRBuilder(); - auto *baseAddr = builder->CreateExprAddrof(0, dassign.GetStIdx()); - auto byteBitOffsets = beCommon.GetFieldOffset(*structTy, dassign.GetFieldID()); - return WriteBitField(byteBitOffsets, static_cast(fType), baseAddr, dassign.GetRHS(), &newBlk); -} - -StmtNode *CGLowerer::LowerIassignBitfield(IassignNode &iassign, BlockNode &newBlk) -{ - DEBUG_ASSERT(iassign.Opnd(0) != nullptr, "iassign.Opnd(0) should not be nullptr"); - iassign.SetOpnd(LowerExpr(iassign, *iassign.Opnd(0), newBlk), 0); - iassign.SetRHS(LowerExpr(iassign, *iassign.GetRHS(), newBlk)); - - CHECK_FATAL(iassign.GetTyIdx() < GlobalTables::GetTypeTable().GetTypeTable().size(), - "LowerIassignBitField: subscript out of range"); - uint32 index = iassign.GetTyIdx(); - MIRPtrType *pointerTy = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(index)); - CHECK_FATAL(pointerTy != nullptr, "LowerIassignBitField: type in iassign should be pointer type"); - MIRType *pointedTy = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointerTy->GetPointedTyIdx()); - /* - * Here pointed type can be Struct or JArray - * We should seriously consider make JArray also a Struct type - */ - MIRStructType *structTy = nullptr; - if (pointedTy->GetKind() != kTypeJArray) { - structTy = static_cast(pointedTy); - } else { - structTy = static_cast(pointedTy)->GetParentType(); - } - - TyIdx fTyIdx = structTy->GetFieldTyIdx(iassign.GetFieldID()); - MIRType *fType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(TyIdx(fTyIdx)); - if (fType->GetKind() != kTypeBitField) { - return &iassign; - } - auto byteBitOffsets = beCommon.GetFieldOffset(*structTy, iassign.GetFieldID()); - auto *bitFieldType = static_cast(fType); - return WriteBitField(byteBitOffsets, bitFieldType, iassign.Opnd(0), iassign.GetRHS(), &newBlk); -} - void CGLowerer::LowerIassign(IassignNode &iassign, BlockNode &newBlk) { StmtNode *newStmt = nullptr; - if (iassign.GetFieldID() != 0) { - newStmt = LowerIassignBitfield(iassign, newBlk); - } else { - LowerStmt(iassign, newBlk); - newStmt = &iassign; - } + CHECK_FATAL(iassign.GetFieldID() == 0, "fieldID must be 0"); + LowerStmt(iassign, newBlk); + newStmt = &iassign; newBlk.AddStatement(newStmt); } @@ -653,226 +538,6 @@ BlockNode *CGLowerer::LowerIntrinsiccallToIntrinsicop(StmtNode &stmt) return nullptr; } -#if TARGAARCH64 -static PrimType IsStructElementSame(MIRType *ty) -{ - if (ty->GetKind() == kTypeArray) { - MIRArrayType *arrtype = static_cast(ty); - MIRType *pty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(arrtype->GetElemTyIdx()); - if (pty->GetKind() == kTypeArray || pty->GetKind() == kTypeStruct) { - return IsStructElementSame(pty); - } - return pty->GetPrimType(); - } else if (ty->GetKind() == kTypeStruct) { - MIRStructType *sttype = static_cast(ty); - FieldVector fields = sttype->GetFields(); - PrimType oldtype = PTY_void; - for (uint32 fcnt = 0; fcnt < fields.size(); ++fcnt) { - TyIdx fieldtyidx = fields[fcnt].second.first; - MIRType *fieldty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldtyidx); - PrimType ptype = IsStructElementSame(fieldty); - if (oldtype != PTY_void && oldtype != ptype) { - return PTY_void; - } else { - oldtype = ptype; - } - } - return oldtype; - } else { - return ty->GetPrimType(); - } -} -#endif - -// return true if successfully lowered -bool CGLowerer::LowerStructReturn(BlockNode &newBlk, StmtNode &stmt, bool &lvar) -{ - CallReturnVector *p2nrets = stmt.GetCallReturnVector(); - if (p2nrets->size() == 0) { - return false; - } - CallReturnPair retPair = (*p2nrets)[0]; - if (retPair.second.IsReg()) { - return false; - } - DEBUG_ASSERT(mirModule.CurFunction() != nullptr, "CurFunction should not be nullptr"); - MIRSymbol *retSym = mirModule.CurFunction()->GetLocalOrGlobalSymbol(retPair.first); - if (retSym->GetType()->GetPrimType() != PTY_agg) { - return false; - } - - if (IsReturnInMemory(*retSym->GetType())) { - lvar = true; - } else if (!LowerStructReturnInRegs(newBlk, stmt, *retSym)) { - return false; - } - return true; -} - -bool CGLowerer::LowerStructReturnInRegs(BlockNode &newBlk, StmtNode &stmt, const MIRSymbol &retSym) -{ - // lower callassigned -> call - if (stmt.GetOpCode() == OP_callassigned) { - auto &callNode = static_cast(stmt); - for (size_t i = 0; i < callNode.GetNopndSize(); ++i) { - auto *newOpnd = LowerExpr(callNode, *callNode.GetNopndAt(i), newBlk); - callNode.SetOpnd(newOpnd, i); - } - auto *callStmt = mirModule.GetMIRBuilder()->CreateStmtCall(callNode.GetPUIdx(), callNode.GetNopnd()); - callStmt->SetSrcPos(callNode.GetSrcPos()); - newBlk.AddStatement(callStmt); - } else if (stmt.GetOpCode() == OP_icallassigned || stmt.GetOpCode() == OP_icallprotoassigned) { - auto &icallNode = static_cast(stmt); - for (size_t i = 0; i < icallNode.GetNopndSize(); ++i) { - auto *newOpnd = LowerExpr(icallNode, *icallNode.GetNopndAt(i), newBlk); - icallNode.SetOpnd(newOpnd, i); - } - IcallNode *icallStmt = nullptr; - if (stmt.GetOpCode() == OP_icallassigned) { - icallStmt = mirModule.GetMIRBuilder()->CreateStmtIcall(icallNode.GetNopnd()); - } else { - icallStmt = mirModule.GetMIRBuilder()->CreateStmtIcallproto(icallNode.GetNopnd(), icallNode.GetRetTyIdx()); - } - icallStmt->SetSrcPos(icallNode.GetSrcPos()); - newBlk.AddStatement(icallStmt); - } else { - return false; - } - - if (Triple::GetTriple().IsAarch64BeOrLe()) { -#if TARGAARCH64 - PrimType primType = PTY_begin; - size_t elemNum = 0; - if (IsHomogeneousAggregates(*retSym.GetType(), primType, elemNum)) { - LowerStructReturnInFpRegs(newBlk, stmt, retSym, primType, elemNum); - } else { - LowerStructReturnInGpRegs(newBlk, stmt, retSym); - } -#endif - } else { - LowerStructReturnInGpRegs(newBlk, stmt, retSym); - } - return true; -} - -// struct passed in gpregs, lowered into -// call &foo -// regassign u64 %1 (regread u64 %%retval0) -// regassign ptr %2 (addrof ptr $s) -// iassign <* u64> 0 (regread ptr %2, regread u64 %1) -void CGLowerer::LowerStructReturnInGpRegs(BlockNode &newBlk, const StmtNode &stmt, const MIRSymbol &symbol) -{ - auto size = static_cast(symbol.GetType()->GetSize()); - if (size == 0) { - return; - } - // save retval0, retval1 - PregIdx pIdx1R = 0; - PregIdx pIdx2R = 0; - DEBUG_ASSERT(GetCurrentFunc() != nullptr, "GetCurrentFunc should not be nullptr"); - auto genRetvalSave = [this, &newBlk](PregIdx &pIdx, SpecialReg sreg) { - auto *regreadNode = mirBuilder->CreateExprRegread(PTY_u64, -sreg); - pIdx = GetCurrentFunc()->GetPregTab()->CreatePreg(PTY_u64); - auto *aStmt = mirBuilder->CreateStmtRegassign(PTY_u64, pIdx, regreadNode); - newBlk.AddStatement(aStmt); - }; - genRetvalSave(pIdx1R, kSregRetval0); - if (size > k8ByteSize) { - genRetvalSave(pIdx2R, kSregRetval1); - } - // save &s - BaseNode *regAddr = mirBuilder->CreateExprAddrof(0, symbol); - LowerTypePtr(*regAddr); - PregIdx pIdxL = GetCurrentFunc()->GetPregTab()->CreatePreg(GetLoweredPtrType()); - auto *aStmt = mirBuilder->CreateStmtRegassign(PTY_a64, pIdxL, regAddr); - newBlk.AddStatement(aStmt); - - // str retval to &s - for (uint32 curSize = 0; curSize < size;) { - // calc addr - BaseNode *addrNode = mirBuilder->CreateExprRegread(GetLoweredPtrType(), pIdxL); - if (curSize != 0) { - MIRType *addrType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(GetLoweredPtrType()); - addrNode = - mirBuilder->CreateExprBinary(OP_add, *addrType, addrNode, mirBuilder->CreateIntConst(curSize, PTY_i32)); - } - - PregIdx pIdxR = (curSize < k8ByteSize) ? pIdx1R : pIdx2R; - uint32 strSize = size - curSize; - // gen str retval to &s + offset - auto genStrRetval2Memory = [this, &newBlk, &addrNode, &curSize, &pIdxR](PrimType primType) { - uint32 shiftSize = (curSize * kBitsPerByte) % k64BitSize; - if (CGOptions::IsBigEndian()) { - shiftSize = k64BitSize - GetPrimTypeBitSize(primType) + shiftSize; - } - BaseNode *regreadExp = mirBuilder->CreateExprRegread(PTY_u64, pIdxR); - if (shiftSize != 0) { - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(PTY_u64); - regreadExp = mirBuilder->CreateExprBinary(OP_lshr, *type, regreadExp, - mirBuilder->CreateIntConst(shiftSize, PTY_i32)); - } - auto *pointedType = GlobalTables::GetTypeTable().GetPrimType(primType); - auto *iassignStmt = mirBuilder->CreateStmtIassign(*beCommon.BeGetOrCreatePointerType(*pointedType), 0, - addrNode, regreadExp); - newBlk.AddStatement(iassignStmt); - curSize += GetPrimTypeSize(primType); - }; - if (strSize >= k8ByteSize) { - genStrRetval2Memory(PTY_u64); - } else if (strSize >= k4ByteSize) { - genStrRetval2Memory(PTY_u32); - } else if (strSize >= k2ByteSize) { - genStrRetval2Memory(PTY_u16); - } else { - genStrRetval2Memory(PTY_u8); - } - } -} - -// struct passed in fpregs, lowered into -// call &foo -// regassign f64 %1 (regread f64 %%retval0) -// regassign ptr %2 (addrof ptr $s) -// iassign <* f64> 0 (regread ptr %2, regread f64 %1) -void CGLowerer::LowerStructReturnInFpRegs(BlockNode &newBlk, const StmtNode &stmt, const MIRSymbol &symbol, - PrimType primType, size_t elemNum) -{ - // save retvals - static constexpr std::array sregs = {kSregRetval0, kSregRetval1, kSregRetval2, kSregRetval3}; - std::vector pIdxs(sregs.size(), 0); - DEBUG_ASSERT(GetCurrentFunc() != nullptr, "GetCurrentFunc should not be nullptr"); - for (uint32 i = 0; i < elemNum; ++i) { - auto *regreadNode = mirBuilder->CreateExprRegread(primType, -sregs[i]); - pIdxs[i] = GetCurrentFunc()->GetPregTab()->CreatePreg(primType); - auto *aStmt = mirBuilder->CreateStmtRegassign(primType, pIdxs[i], regreadNode); - newBlk.AddStatement(aStmt); - } - - // save &s - BaseNode *regAddr = mirBuilder->CreateExprAddrof(0, symbol); - LowerTypePtr(*regAddr); - PregIdx pIdxL = GetCurrentFunc()->GetPregTab()->CreatePreg(GetLoweredPtrType()); - auto *aStmt = mirBuilder->CreateStmtRegassign(PTY_a64, pIdxL, regAddr); - newBlk.AddStatement(aStmt); - - // str retvals to &s - for (uint32 i = 0; i < elemNum; ++i) { - uint32 offsetSize = i * GetPrimTypeSize(primType); - BaseNode *addrNode = mirBuilder->CreateExprRegread(GetLoweredPtrType(), pIdxL); - // addr add offset - if (offsetSize != 0) { - MIRType *addrType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(GetLoweredPtrType()); - addrNode = mirBuilder->CreateExprBinary(OP_add, *addrType, addrNode, - mirBuilder->CreateIntConst(offsetSize, PTY_i32)); - } - // gen iassigen to addr - auto *pointedType = GlobalTables::GetTypeTable().GetPrimType(primType); - auto *iassignStmt = mirBuilder->CreateStmtIassign(*beCommon.BeGetOrCreatePointerType(*pointedType), 0, addrNode, - mirBuilder->CreateExprRegread(PTY_u64, pIdxs[i])); - newBlk.AddStatement(iassignStmt); - } -} - void CGLowerer::LowerStmt(StmtNode &stmt, BlockNode &newBlk) { for (size_t i = 0; i < stmt.NumOpnds(); ++i) { @@ -949,10 +614,7 @@ BlockNode *CGLowerer::LowerBlock(BlockNode &block) case OP_icallprotoassigned: { // pass the addr of lvar if this is a struct call assignment bool lvar = false; - // nextStmt could be changed by the call to LowerStructReturn - if (!LowerStructReturn(*newBlk, *stmt, lvar)) { - newBlk->AppendStatementsFromBlock(*LowerCallAssignedStmt(*stmt, lvar)); - } + newBlk->AppendStatementsFromBlock(*LowerCallAssignedStmt(*stmt, lvar)); break; } case OP_virtualcallassigned: @@ -1077,14 +739,6 @@ StmtNode *CGLowerer::LowerCall(CallNode &callNode, StmtNode *&nextStmt, BlockNod if (isArrayStore && checkLoadStore) { bool needCheckStore = true; - MIRType *arrayElemType = GetArrayNodeType(*callNode.Opnd(0)); - MIRType *valueRealType = GetArrayNodeType(*callNode.Opnd(kNodeThirdOpnd)); - if ((arrayElemType != nullptr) && (valueRealType != nullptr) && (arrayElemType->GetKind() == kTypeClass) && - static_cast(arrayElemType)->IsFinal() && (valueRealType->GetKind() == kTypeClass) && - static_cast(valueRealType)->IsFinal() && - valueRealType->GetTypeIndex() == arrayElemType->GetTypeIndex()) { - needCheckStore = false; - } if (needCheckStore) { MIRFunction *fn = @@ -1116,72 +770,12 @@ StmtNode *CGLowerer::LowerCall(CallNode &callNode, StmtNode *&nextStmt, BlockNod return &callNode; } - MIRType *retType = nullptr; if (callNode.op == OP_icall || callNode.op == OP_icallproto) { if (retTy == nullptr) { return &callNode; - } else { - retType = retTy; } } - if (retType == nullptr) { - MIRFunction *calleeFunc = GlobalTables::GetFunctionTable().GetFunctionFromPuidx(callNode.GetPUIdx()); - retType = calleeFunc->GetReturnType(); - if (calleeFunc->IsReturnStruct() && (retType->GetPrimType() == PTY_void)) { - MIRPtrType *pretType = static_cast((calleeFunc->GetNthParamType(0))); - CHECK_FATAL(pretType != nullptr, "nullptr is not expected"); - retType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pretType->GetPointedTyIdx()); - CHECK_FATAL((retType->GetKind() == kTypeStruct) || (retType->GetKind() == kTypeUnion), - "make sure retType is a struct type"); - } - } - - /* if return type is not of a struct, return */ - if ((retType->GetKind() != kTypeStruct) && (retType->GetKind() != kTypeUnion)) { - return &callNode; - } - - DEBUG_ASSERT(mirModule.CurFunction() != nullptr, "curFunction should not be nullptr"); - MIRSymbol *dsgnSt = mirModule.CurFunction()->GetLocalOrGlobalSymbol(dassignNode->GetStIdx()); - CHECK_FATAL(dsgnSt->GetType()->IsStructType(), "expects a struct type"); - MIRStructType *structTy = static_cast(dsgnSt->GetType()); - if (structTy == nullptr) { - return &callNode; - } - - RegreadNode *regReadNode = nullptr; - if (dassignNode->Opnd(0)->GetOpCode() == OP_regread) { - regReadNode = static_cast(dassignNode->Opnd(0)); - } - if (regReadNode == nullptr || (regReadNode->GetRegIdx() != -kSregRetval0)) { - return &callNode; - } - - MapleVector newNopnd(mirModule.CurFuncCodeMemPoolAllocator()->Adapter()); - AddrofNode *addrofNode = mirModule.CurFuncCodeMemPool()->New(OP_addrof); - addrofNode->SetPrimType(GetLoweredPtrType()); - addrofNode->SetStIdx(dsgnSt->GetStIdx()); - addrofNode->SetFieldID(0); - - if (callNode.op == OP_icall || callNode.op == OP_icallproto) { - auto ond = callNode.GetNopnd().begin(); - newNopnd.emplace_back(*ond); - newNopnd.emplace_back(addrofNode); - for (++ond; ond != callNode.GetNopnd().end(); ++ond) { - newNopnd.emplace_back(*ond); - } - } else { - newNopnd.emplace_back(addrofNode); - for (auto *opnd : callNode.GetNopnd()) { - newNopnd.emplace_back(opnd); - } - } - - callNode.SetNOpnd(newNopnd); - callNode.SetNumOpnds(static_cast(newNopnd.size())); - CHECK_FATAL(nextStmt != nullptr, "nullptr is not expected"); - nextStmt = nextStmt->GetNext(); return &callNode; } @@ -1206,28 +800,6 @@ void CGLowerer::LowerTypePtr(BaseNode &node) const void CGLowerer::LowerEntry(MIRFunction &func) { - // determine if needed to insert fake parameter to return struct for current function - 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) { - func.SetStructReturnedInRegs(); - return; - } - } -#endif - if (retType->GetPrimType() != PTY_agg) { - return; - } - if (retType->GetSize() > k16ByteSize) { - func.SetFirstArgReturn(); - func.GetMIRFuncType()->SetFirstArgReturn(); - } else { - func.SetStructReturnedInRegs(); - } - } if (func.IsFirstArgReturn() && func.GetReturnType()->GetPrimType() != PTY_void) { MIRSymbol *retSt = func.GetSymTab()->CreateSymbol(kScopeLocal); retSt->SetStorageClass(kScFormal); @@ -1461,7 +1033,8 @@ BaseNode *CGLowerer::LowerDread(DreadNode &dread, const BlockNode &block) if (dread.GetPrimType() == PTY_u1) { dread.SetPrimType(PTY_u8); } - return (dread.GetFieldID() == 0 ? LowerDreadToThreadLocal(dread, block) : LowerDreadBitfield(dread)); + CHECK_FATAL(dread.GetFieldID() == 0, "fieldID must be 0"); + return LowerDreadToThreadLocal(dread, block); } void CGLowerer::LowerRegassign(RegassignNode ®Node, BlockNode &newBlk) @@ -1540,21 +1113,16 @@ void CGLowerer::LowerDassign(DassignNode &dsNode, BlockNode &newBlk) StmtNode *newStmt = nullptr; BaseNode *rhs = nullptr; Opcode op = dsNode.GetRHS()->GetOpCode(); - if (dsNode.GetFieldID() != 0) { - newStmt = LowerDassignBitfield(dsNode, newBlk); - } else if (op == OP_intrinsicop) { + CHECK_FATAL(dsNode.GetFieldID() == 0, "fieldID must be 0"); + if (op == OP_intrinsicop) { IntrinsicopNode *intrinNode = static_cast(dsNode.GetRHS()); MIRType *retType = IntrinDesc::intrinTable[intrinNode->GetIntrinsic()].GetReturnType(); CHECK_FATAL(retType != nullptr, "retType should not be nullptr"); - if (retType->GetKind() == kTypeStruct) { - newStmt = LowerIntrinsicopDassign(dsNode, *intrinNode, newBlk); - } else { - rhs = LowerExpr(dsNode, *intrinNode, newBlk); - dsNode.SetRHS(rhs); - CHECK_FATAL(dsNode.GetRHS() != nullptr, "dsNode->rhs is null in CGLowerer::LowerDassign"); - if (!IsDassignNOP(dsNode)) { - newStmt = &dsNode; - } + rhs = LowerExpr(dsNode, *intrinNode, newBlk); + dsNode.SetRHS(rhs); + CHECK_FATAL(dsNode.GetRHS() != nullptr, "dsNode->rhs is null in CGLowerer::LowerDassign"); + if (!IsDassignNOP(dsNode)) { + newStmt = &dsNode; } } else { rhs = LowerExpr(dsNode, *dsNode.GetRHS(), newBlk); @@ -1567,53 +1135,6 @@ void CGLowerer::LowerDassign(DassignNode &dsNode, BlockNode &newBlk) } } -StmtNode *CGLowerer::LowerIntrinsicopDassign(const DassignNode &dsNode, IntrinsicopNode &intrinNode, BlockNode &newBlk) -{ - for (size_t i = 0; i < intrinNode.GetNumOpnds(); ++i) { - DEBUG_ASSERT(intrinNode.Opnd(i) != nullptr, "intrinNode.Opnd(i) should not be nullptr"); - intrinNode.SetOpnd(LowerExpr(intrinNode, *intrinNode.Opnd(i), newBlk), i); - } - MIRIntrinsicID intrnID = intrinNode.GetIntrinsic(); - IntrinDesc *intrinDesc = &IntrinDesc::intrinTable[intrnID]; - MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); - const std::string name = intrinDesc->name; - CHECK_FATAL(intrinDesc->name != nullptr, "intrinDesc's name should not be nullptr"); - st->SetNameStrIdx(name); - st->SetStorageClass(kScText); - st->SetSKind(kStFunc); - MIRFunction *fn = mirModule.GetMemPool()->New(&mirModule, st->GetStIdx()); - MapleVector &nOpnds = intrinNode.GetNopnd(); - st->SetFunction(fn); - std::vector fnTyVec; - std::vector fnTaVec; - CHECK_FATAL(intrinDesc->IsJsOp(), "intrinDesc should be JsOp"); - /* setup parameters */ - for (uint32 i = 0; i < nOpnds.size(); ++i) { - fnTyVec.emplace_back(GlobalTables::GetTypeTable().GetTypeFromTyIdx(PTY_a32)->GetTypeIndex()); - fnTaVec.emplace_back(TypeAttrs()); - BaseNode *addrNode = beCommon.GetAddressOfNode(*nOpnds[i]); - CHECK_FATAL(addrNode != nullptr, "addrNode should not be nullptr"); - nOpnds[i] = addrNode; - } - DEBUG_ASSERT(mirModule.CurFunction() != nullptr, "curFunction should not be nullptr"); - MIRSymbol *dst = mirModule.CurFunction()->GetLocalOrGlobalSymbol(dsNode.GetStIdx()); - MIRType *ty = dst->GetType(); - MIRType *fnType = beCommon.BeGetOrCreateFunctionType(ty->GetTypeIndex(), fnTyVec, fnTaVec); - st->SetTyIdx(fnType->GetTypeIndex()); - fn->SetMIRFuncType(static_cast(fnType)); - fn->SetReturnTyIdx(ty->GetTypeIndex()); - CHECK_FATAL(ty->GetKind() == kTypeStruct, "ty's kind should be struct type"); - CHECK_FATAL(dsNode.GetFieldID() == 0, "dsNode's filedId should equal"); - AddrofNode *addrofNode = mirBuilder->CreateAddrof(*dst, PTY_a32); - MapleVector newOpnd(mirModule.CurFuncCodeMemPoolAllocator()->Adapter()); - newOpnd.emplace_back(addrofNode); - (void)newOpnd.insert(newOpnd.end(), nOpnds.begin(), nOpnds.end()); - CallNode *callStmt = mirModule.CurFuncCodeMemPool()->New(mirModule, OP_call); - callStmt->SetPUIdx(st->GetFunction()->GetPuidx()); - callStmt->SetNOpnd(newOpnd); - return callStmt; -} - StmtNode *CGLowerer::LowerDefaultIntrinsicCall(IntrinsiccallNode &intrincall, MIRSymbol &st, MIRFunction &fn) { MIRIntrinsicID intrnID = intrincall.GetIntrinsic(); @@ -1623,33 +1144,16 @@ StmtNode *CGLowerer::LowerDefaultIntrinsicCall(IntrinsiccallNode &intrincall, MI MapleVector &nOpnds = intrincall.GetNopnd(); MIRType *retTy = intrinDesc->GetReturnType(); CHECK_FATAL(retTy != nullptr, "retTy should not be nullptr"); - if (retTy->GetKind() == kTypeStruct) { - funcTyVec.emplace_back(beCommon.BeGetOrCreatePointerType(*retTy)->GetTypeIndex()); - fnTaVec.emplace_back(TypeAttrs()); - fn.SetReturnStruct(); - } for (uint32 i = 0; i < nOpnds.size(); ++i) { MIRType *argTy = intrinDesc->GetArgType(i); CHECK_FATAL(argTy != nullptr, "argTy should not be nullptr"); - if (argTy->GetKind() == kTypeStruct) { - funcTyVec.emplace_back(GlobalTables::GetTypeTable().GetTypeFromTyIdx(PTY_a32)->GetTypeIndex()); - fnTaVec.emplace_back(TypeAttrs()); - BaseNode *addrNode = beCommon.GetAddressOfNode(*nOpnds[i]); - CHECK_FATAL(addrNode != nullptr, "can not get address"); - nOpnds[i] = addrNode; - } else { - funcTyVec.emplace_back(argTy->GetTypeIndex()); - fnTaVec.emplace_back(TypeAttrs()); - } + funcTyVec.emplace_back(argTy->GetTypeIndex()); + fnTaVec.emplace_back(TypeAttrs()); } MIRType *funcType = beCommon.BeGetOrCreateFunctionType(retTy->GetTypeIndex(), funcTyVec, fnTaVec); st.SetTyIdx(funcType->GetTypeIndex()); fn.SetMIRFuncType(static_cast(funcType)); - if (retTy->GetKind() == kTypeStruct) { - fn.SetReturnTyIdx(static_cast(PTY_void)); - } else { - fn.SetReturnTyIdx(retTy->GetTypeIndex()); - } + fn.SetReturnTyIdx(retTy->GetTypeIndex()); return static_cast(mirBuilder->CreateStmtCall(fn.GetPuidx(), nOpnds)); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cg.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cg.cpp index a00880887b..e4a53df8c1 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cg.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/aarch64/aarch64_cg.cpp @@ -231,21 +231,6 @@ std::string AArch64CG::FindGCTIBPatternName(const std::string &name) const return iter->second->GetName(); } -void AArch64CG::GenerateObjectMaps(BECommon &beCommon) -{ - for (auto &tyId : GetMIRModule()->GetClassList()) { - TyIdx tyIdx(tyId); - MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - DEBUG_ASSERT(ty != nullptr, "ty nullptr check"); - /* Only emit GCTIB for classes owned by this module */ - DEBUG_ASSERT(ty->IsStructType(), "ty isn't MIRStructType* in AArch64CG::GenerateObjectMaps"); - MIRStructType *strTy = static_cast(ty); - if (!strTy->IsLocal()) { - continue; - } - } -} - void AArch64CG::EnrollTargetPhases(MaplePhaseManager *pm) const { if (!GetMIRModule()->IsCModule()) { 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 a21edd16ff..ca7c1a9715 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 @@ -712,24 +712,11 @@ void AArch64CGFunc::SelectDassign(StIdx stIdx, FieldID fieldId, PrimType rhsPTyp MIRSymbol *symbol = GetFunction().GetLocalOrGlobalSymbol(stIdx); int32 offset = 0; bool parmCopy = false; - if (fieldId != 0) { - MIRStructType *structType = static_cast(symbol->GetType()); - DEBUG_ASSERT(structType != nullptr, "SelectDassign: non-zero fieldID for non-structure"); - offset = GetBecommon().GetFieldOffset(*structType, fieldId).first; - parmCopy = IsParamStructCopy(*symbol); - } uint32 regSize = GetPrimTypeBitSize(rhsPType); MIRType *type = symbol->GetType(); Operand &stOpnd = LoadIntoRegister(opnd0, IsPrimitiveInteger(rhsPType), regSize, IsSignedInteger(type->GetPrimType())); MOperator mOp = MOP_undef; - if ((type->GetKind() == kTypeStruct) || (type->GetKind() == kTypeUnion)) { - MIRStructType *structType = static_cast(type); - type = structType->GetFieldType(fieldId); - } else if (type->GetKind() == kTypeClass) { - MIRClassType *classType = static_cast(type); - type = classType->GetFieldType(fieldId); - } uint32 dataSize = GetPrimTypeBitSize(type->GetPrimType()); if (type->GetPrimType() == PTY_agg) { @@ -748,9 +735,7 @@ void AArch64CGFunc::SelectDassign(StIdx stIdx, FieldID fieldId, PrimType rhsPTyp /* In bpl mode, a func symbol's type is represented as a MIRFuncType instead of a MIRPtrType (pointing to * MIRFuncType), so we allow `kTypeFunction` to appear here */ DEBUG_ASSERT(((type->GetKind() == kTypeScalar) || (type->GetKind() == kTypePointer) || - (type->GetKind() == kTypeFunction) || (type->GetKind() == kTypeStruct) || - (type->GetKind() == kTypeUnion) || (type->GetKind() == kTypeArray)), - "NYI dassign type"); + (type->GetKind() == kTypeFunction) || (type->GetKind() == kTypeArray)), "NYI dassign type"); PrimType ptyp = type->GetPrimType(); if (ptyp == PTY_agg) { ptyp = PTY_a64; @@ -823,19 +808,6 @@ void AArch64CGFunc::SelectRegassign(RegassignNode &stmt, Operand &opnd0) } } -MemOperand *AArch64CGFunc::GenFormalMemOpndWithSymbol(const MIRSymbol &sym, int64 offset) -{ - MemOperand *memOpnd = nullptr; - if (IsParamStructCopy(sym)) { - memOpnd = &GetOrCreateMemOpnd(sym, 0, k64BitSize); - RegOperand *vreg = &CreateVirtualRegisterOperand(NewVReg(kRegTyInt, k8ByteSize)); - Insn &ldInsn = GetInsnBuilder()->BuildInsn(PickLdInsn(k64BitSize, PTY_i64), *vreg, *memOpnd); - GetCurBB()->AppendInsn(ldInsn); - return CreateMemOperand(k64BitSize, *vreg, CreateImmOperand(offset, k32BitSize, false), sym.IsVolatile()); - } - return &GetOrCreateMemOpnd(sym, offset, k64BitSize); -} - CCImpl *AArch64CGFunc::GetOrCreateLocator(CallConvKind cc) { auto it = hashCCTable.find(cc); @@ -876,22 +848,7 @@ void AArch64CGFunc::SelectIassign(IassignNode &stmt) DEBUG_ASSERT(pointerType != nullptr, "expect a pointer type at iassign node"); MIRType *pointedType = nullptr; bool isRefField = false; - - if (stmt.GetFieldID() != 0) { - MIRType *pointedTy = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointerType->GetPointedTyIdx()); - MIRStructType *structType = nullptr; - if (pointedTy->GetKind() != kTypeJArray) { - structType = static_cast(pointedTy); - } else { - structType = static_cast(pointedTy)->GetParentType(); - } - DEBUG_ASSERT(structType != nullptr, "SelectIassign: non-zero fieldID for non-structure"); - pointedType = structType->GetFieldType(stmt.GetFieldID()); - offset = GetBecommon().GetFieldOffset(*structType, stmt.GetFieldID()).first; - isRefField = GetBecommon().IsRefField(*structType, stmt.GetFieldID()); - } else { - pointedType = GetPointedToType(*pointerType); - } + pointedType = GetPointedToType(*pointerType); PrimType styp = stmt.GetRHS()->GetPrimType(); Operand *valOpnd = HandleExpr(stmt, *stmt.GetRHS()); @@ -917,13 +874,6 @@ Operand *AArch64CGFunc::SelectDread(const BaseNode &parent, DreadNode &expr) PrimType symType = symbol->GetType()->GetPrimType(); uint32 offset = 0; bool parmCopy = false; - if (expr.GetFieldID() != 0) { - MIRStructType *structType = static_cast(symbol->GetType()); - DEBUG_ASSERT(structType != nullptr, "SelectDread: non-zero fieldID for non-structure"); - symType = structType->GetFieldType(expr.GetFieldID())->GetPrimType(); - offset = static_cast(GetBecommon().GetFieldOffset(*structType, expr.GetFieldID()).first); - parmCopy = IsParamStructCopy(*symbol); - } uint32 dataSize = GetPrimTypeBitSize(symType); uint32 aggSize = 0; @@ -1014,22 +964,7 @@ Operand *AArch64CGFunc::SelectIread(const BaseNode &parent, IreadNode &expr, int MIRType *pointedType = nullptr; bool isRefField = false; - if (expr.GetFieldID() != 0) { - MIRType *pointedTy = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointerType->GetPointedTyIdx()); - MIRStructType *structType = nullptr; - if (pointedTy->GetKind() != kTypeJArray) { - structType = static_cast(pointedTy); - } else { - structType = static_cast(pointedTy)->GetParentType(); - } - - DEBUG_ASSERT(structType != nullptr, "SelectIread: non-zero fieldID for non-structure"); - pointedType = structType->GetFieldType(expr.GetFieldID()); - offset = GetBecommon().GetFieldOffset(*structType, expr.GetFieldID()).first; - isRefField = GetBecommon().IsRefField(*structType, expr.GetFieldID()); - } else { - pointedType = GetPointedToType(*pointerType); - } + pointedType = GetPointedToType(*pointerType); RegType regType = GetRegTyFromPrimTy(expr.GetPrimType()); uint32 regSize = GetPrimTypeSize(expr.GetPrimType()); @@ -1061,13 +996,7 @@ Operand *AArch64CGFunc::SelectIread(const BaseNode &parent, IreadNode &expr, int bitSize = GetPrimTypeBitSize(expr.GetPrimType()); maple::LogInfo::MapleLogger(kLlErr) << "Warning: objsize is zero! \n"; } else { - if (pointedType->IsStructType()) { - MIRStructType *structType = static_cast(pointedType); - /* size << 3, that is size * 8, change bytes to bits */ - bitSize = std::min(structType->GetSize(), static_cast(GetPointerSize())) << 3; - } else { - bitSize = GetPrimTypeBitSize(destType); - } + bitSize = GetPrimTypeBitSize(destType); if (regType == kRegTyFloat) { destType = expr.GetPrimType(); bitSize = GetPrimTypeBitSize(destType); 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 8acd5ec3e0..04188bd9d7 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 @@ -61,32 +61,11 @@ uint32 AArch64MemLayout::ComputeStackSpaceRequirementForCall(StmtNode &stmt, int CHECK_NULL_FATAL(be.GetMIRModule().CurFunction()); MIRSymbol *sym = be.GetMIRModule().CurFunction()->GetLocalOrGlobalSymbol(dread->GetStIdx()); ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(sym->GetTyIdx()); - if (dread->GetFieldID() != 0) { - DEBUG_ASSERT(ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeClass || - ty->GetKind() == kTypeUnion, - "expect struct or class"); - if (ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeUnion) { - ty = static_cast(ty)->GetFieldType(dread->GetFieldID()); - } else { - ty = static_cast(ty)->GetFieldType(dread->GetFieldID()); - } - } } else if (opndOpcode == OP_iread) { IreadNode *iread = static_cast(opnd); ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(iread->GetTyIdx()); DEBUG_ASSERT(ty->GetKind() == kTypePointer, "expect pointer"); ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast(ty)->GetPointedTyIdx()); - if (iread->GetFieldID() != 0) { - DEBUG_ASSERT(ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeClass || - ty->GetKind() == kTypeUnion, - "expect struct or class"); - CHECK_NULL_FATAL(ty); - if (ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeUnion) { - ty = static_cast(ty)->GetFieldType(iread->GetFieldID()); - } else { - ty = static_cast(ty)->GetFieldType(iread->GetFieldID()); - } - } } if (ty == nullptr) { /* type mismatch */ continue; 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 0932ee5ba9..b87e72659d 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 @@ -195,10 +195,6 @@ bool CGOptions::SolveOptions() opts::cg::cg ? SetOption(CGOptions::kDoCg) : ClearOption(CGOptions::kDoCg); } - if (opts::cg::objmap.IsEnabledByUser()) { - SetGenerateObjectMap(opts::cg::objmap); - } - if (opts::cg::generalRegOnly.IsEnabledByUser()) { opts::cg::generalRegOnly ? EnableGeneralRegOnly() : DisableGeneralRegOnly(); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp index d153a65c71..23315524f6 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cg_options.cpp @@ -55,12 +55,6 @@ maplecl::Option hotFix({"--hot-fix"}, " --no-hot-fix\n", {cgCategory}, maplecl::DisableWith("--no-hot-fix")); -maplecl::Option objmap({"--objmap"}, - " --objmap" - " \tCreate object maps (GCTIBs) inside the main output (.s) file\n" - " --no-objmap\n", - {cgCategory}, maplecl::DisableWith("--no-objmap")); - maplecl::Option yieldpoint({"--yieldpoint"}, " --yieldpoint \tGenerate yieldpoints [default]\n" " --no-yieldpoint\n", 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 1e63e7cb6e..c65e3d24cc 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 @@ -382,9 +382,6 @@ void CgFuncPM::DumpFuncCGIR(const CGFunc &f, const std::string &phaseName) const void CgFuncPM::EmitGlobalInfo(MIRModule &m) const { EmitDuplicatedAsmFunc(m); - if (cgOptions->IsGenerateObjectMap()) { - cg->GenerateObjectMaps(*beCommon); - } cg->template Emit([](Emitter* emitter) { emitter->EmitGlobalVariable(); emitter->CloseOutput(); diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cgfunc.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cgfunc.cpp index 1b34449d0b..c0240422de 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/cgfunc.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/cgfunc.cpp @@ -79,15 +79,6 @@ void MemRWNodeHelper::GetMemRWNodeBaseInfo(const BaseNode &node, MIRFunction &mi void MemRWNodeHelper::GetTrueMirInfo(const BECommon &beCommon) { - // fixup mirType, primType and offset - if (fieldId != 0) { // get true field type - DEBUG_ASSERT((mirType->IsMIRStructType() || mirType->IsMIRUnionType()), - "non-structure"); - auto *structType = static_cast(mirType); - mirType = structType->GetFieldType(fieldId); - byteOffset = static_cast(structType->GetFieldOffsetFromBaseAddr(fieldId).byteOffset); - isRefField = beCommon.IsRefField(*structType, fieldId); - } primType = mirType->GetPrimType(); // get mem size memSize = static_cast(mirType->GetSize()); @@ -451,7 +442,6 @@ static void HandleReturn(StmtNode &stmt, CGFunc &cgFunc) DEBUG_ASSERT(retNode.NumOpnds() <= 1, "NYI return nodes number > 1"); Operand *opnd = nullptr; if (retNode.NumOpnds() != 0) { - CHECK_FATAL(!cgFunc.GetFunction().StructReturnedInRegs(), "NIY"); opnd = cgFunc.HandleExpr(retNode, *retNode.Opnd(0)); } cgFunc.SelectReturn(opnd); 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 a550f7dab8..eb2e2916d9 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/emit.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/emit.cpp @@ -373,19 +373,8 @@ void Emitter::EmitAsmLabel(const MIRSymbol &mirSymbol, AsmLabel label) emit(align.c_str()); #else /* ELF */ /* output align, symbol name begin with "classInitProtectRegion" align is 4096 */ - MIRTypeKind kind = mirSymbol.GetType()->GetKind(); - MIRStorageClass storage = mirSymbol.GetStorageClass(); if (symName.find("classInitProtectRegion") == 0) { Emit(4096); // symbol name begin with "classInitProtectRegion" align is 4096 - } else if (((kind == kTypeStruct) || (kind == kTypeClass) || (kind == kTypeArray) || - (kind == kTypeUnion)) && - ((storage == kScGlobal) || (storage == kScPstatic) || (storage == kScFstatic))) { - int32 align = Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex()); - if (GetPointerSize() < align) { - (void)Emit(std::to_string(align)); - } else { - (void)Emit(std::to_string(k8ByteSize)); - } } else { (void)Emit( std::to_string(Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirType->GetTypeIndex()))); @@ -397,22 +386,13 @@ void Emitter::EmitAsmLabel(const MIRSymbol &mirSymbol, AsmLabel label) case kAsmAlign: { uint8 align = mirSymbol.GetAttrs().GetAlignValue(); if (align == 0) { - if (mirSymbol.GetType()->GetKind() == kTypeStruct || mirSymbol.GetType()->GetKind() == kTypeClass || - mirSymbol.GetType()->GetKind() == kTypeArray || mirSymbol.GetType()->GetKind() == kTypeUnion) { - if (GetCG()->GetTargetMachine()->isX8664()) { - return; - } else { + align = Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirSymbol.GetType()->GetTypeIndex()); + 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 = Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirSymbol.GetType()->GetTypeIndex()); - 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)); - } + } else { + align = static_cast(log2(align)); } } } @@ -848,12 +828,6 @@ void Emitter::EmitScalarConstant(MIRConst &mirConst, bool newLine, bool flag32, if (symAddr.GetOffset() != 0) { (void)Emit(" + ").Emit(symAddr.GetOffset()); } - if (symAddr.GetFieldID() > 1) { - MIRStructType *structType = static_cast(symAddrSym->GetType()); - DEBUG_ASSERT(structType != nullptr, "EmitScalarConstant: non-zero fieldID for non-structure"); - (void)Emit(" + ").Emit( - Globals::GetInstance()->GetBECommon()->GetFieldOffset(*structType, symAddr.GetFieldID()).first); - } break; } case kConstAddrofFunc: { @@ -1343,23 +1317,9 @@ int64 Emitter::GetFieldOffsetValue(const std::string &className, const MIRIntCon uint64 idx = static_cast(intConst.GetExtValue()); bool isDefTabIndex = idx & 0x1; int64 fieldIdx = idx >> 1; - if (isDefTabIndex) { - /* it's def table index. */ - return fieldIdx; - } else { - /* really offset. */ - uint8 charBitWidth = GetPrimTypeSize(PTY_i8) * kBitsPerByte; - GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(className); - auto it = strIdx2Type.find(strIdx); - CHECK_FATAL(it->second != nullptr, "valid iterator check"); - DEBUG_ASSERT(it != strIdx2Type.end(), "Can not find type"); - MIRType &ty = *it->second; - MIRStructType &structType = static_cast(ty); - std::pair fieldOffsetPair = - Globals::GetInstance()->GetBECommon()->GetFieldOffset(structType, fieldIdx); - int64 fieldOffset = fieldOffsetPair.first * static_cast(charBitWidth) + fieldOffsetPair.second; - return fieldOffset; - } + CHECK_FATAL(isDefTabIndex > 0, "isDefTabIndex > 0"); + /* it's def table index. */ + return fieldIdx; #else return 0; #endif @@ -1703,7 +1663,7 @@ void Emitter::EmitConstantTable(const MIRSymbol &mirSymbol, MIRConst &mirConst, } else { /* intconst */ EmitIntConst(mirSymbol, aggConst, itabConflictIndex, strIdx2Type, i); } - } else if (elemConst->GetType().GetKind() == kTypeArray || elemConst->GetType().GetKind() == kTypeStruct) { + } else if (elemConst->GetType().GetKind() == kTypeArray) { if (StringUtils::StartsWith(mirSymbol.GetName(), namemangler::kOffsetTabStr) && (i == 0 || i == 1)) { /* EmitOffsetValueTable */ #ifdef USE_32BIT_REF @@ -1761,9 +1721,6 @@ void Emitter::EmitArrayConstant(MIRConst &mirConst) } } else if (elemConst->GetType().GetKind() == kTypeArray) { EmitArrayConstant(*elemConst); - } else if (elemConst->GetType().GetKind() == kTypeStruct || elemConst->GetType().GetKind() == kTypeClass || - elemConst->GetType().GetKind() == kTypeUnion) { - EmitStructConstant(*elemConst); } else if (elemConst->GetKind() == kConstAddrofFunc) { EmitScalarConstant(*elemConst); } else { @@ -1792,125 +1749,6 @@ void Emitter::EmitArrayConstant(MIRConst &mirConst) #endif } -void Emitter::EmitStructConstant(MIRConst &mirConst) -{ -#ifdef ARK_LITECG_DEBUG - uint32_t subStructFieldCounts = 0; - EmitStructConstant(mirConst, subStructFieldCounts); -#endif -} - -void Emitter::EmitStructConstant(MIRConst &mirConst, uint32 &subStructFieldCounts) -{ -#ifdef ARK_LITECG_DEBUG - StructEmitInfo *sEmitInfo = cg->GetMIRModule()->GetMemPool()->New(); - CHECK_FATAL(sEmitInfo != nullptr, "create a new struct emit info failed in Emitter::EmitStructConstant"); - MIRType &mirType = mirConst.GetType(); - MIRAggConst &structCt = static_cast(mirConst); - MIRStructType &structType = static_cast(mirType); - auto structPack = static_cast(structType.GetTypeAttrs().GetPack()); - /* all elements of struct. */ - uint8 num; - if (structType.GetKind() == kTypeUnion) { - num = 1; - } else { - num = static_cast(structType.GetFieldsSize()); - } - BECommon *beCommon = Globals::GetInstance()->GetBECommon(); - /* total size of emitted elements size. */ - uint32 size = beCommon->GetTypeSize(structType.GetTypeIndex()); - uint32 fieldIdx = 1; - if (structType.GetKind() == kTypeUnion) { - fieldIdx = structCt.GetFieldIdItem(0); - } - for (uint32 i = 0; i < num; ++i) { - if (((i + 1) == num) && cg->GetMIRModule()->GetSrcLang() == kSrcLangC) { - isFlexibleArray = beCommon->GetHasFlexibleArray(mirType.GetTypeIndex().GetIdx()); - arraySize = 0; - } - MIRConst *elemConst; - if (structType.GetKind() == kTypeStruct) { - elemConst = structCt.GetAggConstElement(i + 1); - } else { - elemConst = structCt.GetAggConstElement(fieldIdx); - } - MIRType *elemType = structType.GetElemType(i); - if (structType.GetKind() == kTypeUnion) { - CHECK_NULL_FATAL(elemConst); - elemType = &(elemConst->GetType()); - } - MIRType *nextElemType = nullptr; - if (i != static_cast(num - 1)) { - nextElemType = structType.GetElemType(i + 1); - } - uint64 elemSize = beCommon->GetTypeSize(elemType->GetTypeIndex()); - uint8 charBitWidth = GetPrimTypeSize(PTY_i8) * kBitsPerByte; - if (elemType->GetKind() == kTypeBitField) { - if (elemConst == nullptr) { - MIRIntConst *zeroFill = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *elemType); - elemConst = zeroFill; - } - std::pair fieldOffsetPair = beCommon->GetFieldOffset(structType, fieldIdx); - uint64_t fieldOffset = static_cast(static_cast(fieldOffsetPair.first)) * - static_cast(charBitWidth) + - static_cast(static_cast(fieldOffsetPair.second)); - EmitBitFieldConstant(*sEmitInfo, *elemConst, nextElemType, fieldOffset); - } else { - if (elemConst != nullptr) { - if (IsPrimitiveScalar(elemType->GetPrimType())) { - EmitScalarConstant(*elemConst, true, false, true); - } else if (elemType->GetKind() == kTypeArray) { - if (elemType->GetSize() != 0) { - EmitArrayConstant(*elemConst); - } - } else if ((elemType->GetKind() == kTypeStruct) || (elemType->GetKind() == kTypeClass) || - (elemType->GetKind() == kTypeUnion)) { - EmitStructConstant(*elemConst, subStructFieldCounts); - fieldIdx += subStructFieldCounts; - } else { - DEBUG_ASSERT(false, "should not run here"); - } - } else { - EmitNullConstant(elemSize); - } - sEmitInfo->IncreaseTotalSize(elemSize); - sEmitInfo->SetNextFieldOffset(sEmitInfo->GetTotalSize() * charBitWidth); - } - - if (nextElemType != nullptr && kTypeBitField != nextElemType->GetKind()) { - DEBUG_ASSERT(i < static_cast(num - 1), "NYI"); - uint8 nextAlign = Globals::GetInstance()->GetBECommon()->GetTypeAlign(nextElemType->GetTypeIndex()); - auto fieldAttr = structType.GetFields()[i + 1].second.second; - nextAlign = fieldAttr.IsPacked() ? 1 : std::min(nextAlign, structPack); - DEBUG_ASSERT(nextAlign != 0, "expect non-zero"); - /* append size, append 0 when align need. */ - uint64 totalSize = sEmitInfo->GetTotalSize(); - uint64 psize = (totalSize % nextAlign == 0) ? 0 : (nextAlign - (totalSize % nextAlign)); - if (psize != 0) { - EmitNullConstant(psize); - sEmitInfo->IncreaseTotalSize(psize); - sEmitInfo->SetNextFieldOffset(sEmitInfo->GetTotalSize() * charBitWidth); - } - /* element is uninitialized, emit null constant. */ - } - fieldIdx++; - } - if (structType.GetKind() == kTypeStruct) { - /* The reason of subtracting one is that fieldIdx adds one at the end of the cycle. */ - CHECK_FATAL(fieldIdx > 0, "must not be zero"); - subStructFieldCounts = fieldIdx - 1; - } else if (structType.GetKind() == kTypeUnion) { - subStructFieldCounts = static_cast(beCommon->GetStructFieldCount(structType.GetTypeIndex())); - } - - isFlexibleArray = false; - uint64 opSize = size - sEmitInfo->GetTotalSize(); - if (opSize != 0) { - EmitNullConstant(opSize); - } -#endif -} - /* BlockMarker is for Debugging/Profiling */ void Emitter::EmitBlockMarker(const std::string &markerName, const std::string §ionName, bool withAddr, const std::string &addrName) @@ -2314,10 +2152,6 @@ void Emitter::EmitLocalVariable(const CGFunc &cgFunc) MIRConst *ct = st->GetKonst(); if (ct == nullptr) { EmitAsmLabel(*st, kAsmComm); - } else if (kTypeStruct == ty->GetKind() || kTypeUnion == ty->GetKind() || - kTypeClass == ty->GetKind()) { - EmitAsmLabel(*st, kAsmSyname); - EmitStructConstant(*ct); } else if (kTypeArray == ty->GetKind()) { if (ty->GetSize() != 0) { EmitAsmLabel(*st, kAsmSyname); @@ -2727,13 +2561,6 @@ void Emitter::EmitGlobalVariable() } else { EmitArrayConstant(*mirConst); } - } else if (mirType->GetKind() == kTypeStruct || mirType->GetKind() == kTypeClass || - mirType->GetKind() == kTypeUnion) { - if (mirSymbol->HasAddrOfValues()) { - EmitConstantTable(*mirSymbol, *mirConst, strIdx2Type); - } else { - EmitStructConstant(*mirConst); - } } else { DEBUG_ASSERT(false, "NYI"); } @@ -2769,10 +2596,6 @@ void Emitter::EmitGlobalVariable() } else if (kTypeArray == mirType->GetKind()) { EmitAsmLabel(*mirSymbol, kAsmSyname); EmitArrayConstant(*ct); - } else if (kTypeStruct == mirType->GetKind() || kTypeClass == mirType->GetKind() || - kTypeUnion == mirType->GetKind()) { - EmitAsmLabel(*mirSymbol, kAsmSyname); - EmitStructConstant(*ct); } else { CHECK_FATAL(0, "Unknown type in Global pstatic"); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/isel.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/isel.cpp index 0625f0d5cb..42656305b4 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/isel.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/isel.cpp @@ -616,12 +616,6 @@ MirTypeInfo MPISel::GetMirTypeInfoFormFieldIdAndMirType(FieldID fieldId, MIRType { MirTypeInfo mirTypeInfo; /* fixup primType and offset */ - if (fieldId != 0) { - DEBUG_ASSERT((mirType->IsMIRStructType() || mirType->IsMIRUnionType()), "non-structure"); - MIRStructType *structType = static_cast(mirType); - mirType = structType->GetFieldType(fieldId); - mirTypeInfo.offset = static_cast(cgFunc->GetBecommon().GetFieldOffset(*structType, fieldId).first); - } mirTypeInfo.primType = mirType->GetPrimType(); // aggSize for AggType if (mirTypeInfo.primType == maple::PTY_agg) { diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_MPIsel.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_MPIsel.cpp index 8e4c23e3df..0bd6b6d34b 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_MPIsel.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_MPIsel.cpp @@ -26,15 +26,8 @@ MemOperand &X64MPIsel::GetOrCreateMemOpndFromSymbol(const MIRSymbol &symbol, Fie { PrimType symType; int32 fieldOffset = 0; - if (fieldId == 0) { - symType = symbol.GetType()->GetPrimType(); - } else { - MIRType *mirType = symbol.GetType(); - DEBUG_ASSERT((mirType->IsMIRStructType() || mirType->IsMIRUnionType()), "non-structure"); - MIRStructType *structType = static_cast(mirType); - symType = structType->GetFieldType(fieldId)->GetPrimType(); - fieldOffset = static_cast(cgFunc->GetBecommon().GetFieldOffset(*structType, fieldId).first); - } + CHECK_FATAL(fieldId == 0, "fieldId must be 0"); + symType = symbol.GetType()->GetPrimType(); uint32 opndSz = (symType == PTY_agg) ? k64BitSize : GetPrimTypeBitSize(symType); return GetOrCreateMemOpndFromSymbol(symbol, opndSz, fieldOffset); } @@ -79,45 +72,13 @@ void X64MPIsel::SelectReturn(NaryStmtNode &retNode, Operand &opnd) return; } std::vector retRegs; - if (!cgFunc->GetFunction().StructReturnedInRegs() || retNode.Opnd(0)->GetOpCode() == OP_constval) { - PrimType oriPrimType = retMech.GetPrimTypeOfReg0(); - regno_t retReg = retMech.GetReg0(); - DEBUG_ASSERT(retReg != kRinvalid, "NIY"); - RegOperand &retOpnd = cgFunc->GetOpndBuilder()->CreatePReg(retReg, GetPrimTypeBitSize(oriPrimType), - cgFunc->GetRegTyFromPrimTy(oriPrimType)); - retRegs.push_back(&retOpnd); - SelectCopy(retOpnd, opnd, oriPrimType, retNode.Opnd(0)->GetPrimType()); - } else { - CHECK_FATAL(opnd.IsMemoryAccessOperand(), "NIY"); - MemOperand &memOpnd = static_cast(opnd); - ImmOperand *offsetOpnd = memOpnd.GetOffsetOperand(); - RegOperand *baseOpnd = memOpnd.GetBaseRegister(); - - PrimType oriPrimType0 = retMech.GetPrimTypeOfReg0(); - regno_t retReg0 = retMech.GetReg0(); - DEBUG_ASSERT(retReg0 != kRinvalid, "NIY"); - RegOperand &retOpnd0 = cgFunc->GetOpndBuilder()->CreatePReg(retReg0, GetPrimTypeBitSize(oriPrimType0), - cgFunc->GetRegTyFromPrimTy(oriPrimType0)); - MemOperand &rhsMemOpnd0 = cgFunc->GetOpndBuilder()->CreateMem(GetPrimTypeBitSize(oriPrimType0)); - rhsMemOpnd0.SetBaseRegister(*baseOpnd); - rhsMemOpnd0.SetOffsetOperand(*offsetOpnd); - retRegs.push_back(&retOpnd0); - SelectCopy(retOpnd0, rhsMemOpnd0, oriPrimType0); - - regno_t retReg1 = retMech.GetReg1(); - if (retReg1 != kRinvalid) { - PrimType oriPrimType1 = retMech.GetPrimTypeOfReg1(); - RegOperand &retOpnd1 = cgFunc->GetOpndBuilder()->CreatePReg(retReg1, GetPrimTypeBitSize(oriPrimType1), - cgFunc->GetRegTyFromPrimTy(oriPrimType1)); - MemOperand &rhsMemOpnd1 = cgFunc->GetOpndBuilder()->CreateMem(GetPrimTypeBitSize(oriPrimType1)); - ImmOperand &newOffsetOpnd = static_cast(*offsetOpnd->Clone(*cgFunc->GetMemoryPool())); - newOffsetOpnd.SetValue(newOffsetOpnd.GetValue() + GetPrimTypeSize(oriPrimType0)); - rhsMemOpnd1.SetBaseRegister(*baseOpnd); - rhsMemOpnd1.SetOffsetOperand(newOffsetOpnd); - retRegs.push_back(&retOpnd1); - SelectCopy(retOpnd1, rhsMemOpnd1, oriPrimType1); - } - } + PrimType oriPrimType = retMech.GetPrimTypeOfReg0(); + regno_t retReg = retMech.GetReg0(); + DEBUG_ASSERT(retReg != kRinvalid, "NIY"); + RegOperand &retOpnd = cgFunc->GetOpndBuilder()->CreatePReg(retReg, GetPrimTypeBitSize(oriPrimType), + cgFunc->GetRegTyFromPrimTy(oriPrimType)); + retRegs.push_back(&retOpnd); + SelectCopy(retOpnd, opnd, oriPrimType, retNode.Opnd(0)->GetPrimType()); /* for optimization ,insert pseudo ret ,in case rax,rdx is removed*/ SelectPseduoForReturn(retRegs); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cg.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cg.cpp index d73eca78e8..fa05c38a3e 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cg.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_cg.cpp @@ -79,9 +79,6 @@ bool X64CG::IsExclusiveFunc(MIRFunction &mirFunc) return false; } -/* NOTE: Consider making be_common a field of CG. */ -void X64CG::GenerateObjectMaps(BECommon &beCommon) {} - /* Used for GCTIB pattern merging */ std::string X64CG::FindGCTIBPatternName(const std::string &name) const { 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 fe0495bb48..5ab7a8ece8 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 @@ -28,15 +28,14 @@ uint8 X64Emitter::GetSymbolAlign(const MIRSymbol &mirSymbol, bool isComm) MIRTypeKind kind = mirSymbol.GetType()->GetKind(); if (isComm) { MIRStorageClass storage = mirSymbol.GetStorageClass(); - if (((kind == kTypeStruct) || (kind == kTypeClass) || (kind == kTypeArray) || (kind == kTypeUnion)) && - ((storage == kScGlobal) || (storage == kScPstatic) || (storage == kScFstatic)) && + if ((kind == kTypeArray) && ((storage == kScGlobal) || (storage == kScPstatic) || (storage == kScFstatic)) && alignInByte < kSizeOfPTR) { alignInByte = kQ; return alignInByte; } } if (alignInByte == 0) { - if (kind == kTypeStruct || kind == kTypeClass || kind == kTypeArray || kind == kTypeUnion) { + if (kind == kTypeArray) { return alignInByte; } else { alignInByte = Globals::GetInstance()->GetBECommon()->GetTypeAlign(mirSymbol.GetType()->GetTypeIndex()); @@ -1544,104 +1543,6 @@ void X64Emitter::EmitFunctionFoot(CGFunc &cgFunc) assmbler.EmitFunctionFoot(symIdx, funcAttr); } -uint64 X64Emitter::EmitStructure(MIRConst &mirConst, CG &cg, bool belongsToDataSec) -{ - uint32 subStructFieldCounts = 0; - uint64 valueSize = EmitStructure(mirConst, cg, subStructFieldCounts, belongsToDataSec); - return valueSize; -} - -uint64 X64Emitter::EmitStructure(MIRConst &mirConst, CG &cg, uint32 &subStructFieldCounts, bool belongsToDataSec) -{ - uint64 valueSize = 0; -#ifdef ARK_LITECG_DEBUG - StructEmitInfo *sEmitInfo = cg.GetMIRModule()->GetMemPool()->New(); - CHECK_NULL_FATAL(sEmitInfo); - MIRType &mirType = mirConst.GetType(); - MIRAggConst &structCt = static_cast(mirConst); - MIRStructType &structType = static_cast(mirType); - uint8 structPack = static_cast(structType.GetTypeAttrs().GetPack()); - MIRTypeKind structKind = structType.GetKind(); - /* all elements of struct. */ - uint8 num = structKind == kTypeUnion ? 1 : static_cast(structType.GetFieldsSize()); - BECommon *beCommon = Globals::GetInstance()->GetBECommon(); - /* total size of emitted elements size. */ - uint64 sizeInByte = GetSymbolSize(structType.GetTypeIndex()); - uint32 fieldIdx = structKind == kTypeUnion ? structCt.GetFieldIdItem(0) : 1; - for (uint32 i = 0; i < num; ++i) { - MIRConst *elemConst = - structKind == kTypeStruct ? structCt.GetAggConstElement(i + 1) : structCt.GetAggConstElement(fieldIdx); - DEBUG_ASSERT(elemConst != nullptr, "elemConst should not be nullptr"); - MIRType *elemType = structKind == kTypeUnion ? &(elemConst->GetType()) : structType.GetElemType(i); - MIRType *nextElemType = i != static_cast(num - 1) ? structType.GetElemType(i + 1) : nullptr; - uint64 elemSize = GetSymbolSize(elemType->GetTypeIndex()); - uint8 charBitWidth = GetPrimTypeSize(PTY_i8) * k8Bits; - MIRTypeKind elemKind = elemType->GetKind(); - if (elemKind == kTypeBitField) { - if (elemConst == nullptr) { - MIRIntConst *zeroFill = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *elemType); - elemConst = zeroFill; - } - pair fieldOffsetPair = beCommon->GetFieldOffset(structType, fieldIdx); - uint64 fieldOffset = - static_cast(static_cast(fieldOffsetPair.first)) * static_cast(charBitWidth) + - static_cast(static_cast(fieldOffsetPair.second)); - EmitBitField(*sEmitInfo, *elemConst, nextElemType, fieldOffset); - } else { - if (elemConst != nullptr) { - if (IsPrimitiveScalar(elemType->GetPrimType())) { - valueSize += EmitSingleElement(*elemConst, belongsToDataSec, true); - } else if (elemKind == kTypeArray) { - if (elemType->GetSize() != 0) { - valueSize += EmitArray(*elemConst, cg, belongsToDataSec); - } - } else if (elemKind == kTypeStruct || elemKind == kTypeClass || elemKind == kTypeUnion) { - valueSize += EmitStructure(*elemConst, cg, subStructFieldCounts, belongsToDataSec); - fieldIdx += subStructFieldCounts; - } else { - DEBUG_ASSERT(false, "should not run here"); - } - } else { - assmbler.EmitNull(elemSize); - } - sEmitInfo->IncreaseTotalSize(elemSize); - sEmitInfo->SetNextFieldOffset(sEmitInfo->GetTotalSize() * charBitWidth); - } - - if (nextElemType != nullptr && nextElemType->GetKind() != kTypeBitField) { - DEBUG_ASSERT(i < static_cast(num - 1), "NYI"); - uint8 nextAlign = Globals::GetInstance()->GetBECommon()->GetTypeAlign(nextElemType->GetTypeIndex()); - auto fieldAttr = structType.GetFields()[i + 1].second.second; - nextAlign = fieldAttr.IsPacked() ? 1 : min(nextAlign, structPack); - DEBUG_ASSERT(nextAlign != 0, "expect non-zero"); - /* append size, append 0 when align need. */ - uint64 totalSize = sEmitInfo->GetTotalSize(); - uint64 psize = (totalSize % nextAlign == 0) ? 0 : (nextAlign - (totalSize % nextAlign)); - /* element is uninitialized, emit null constant. */ - if (psize != 0) { - assmbler.EmitNull(psize); - sEmitInfo->IncreaseTotalSize(psize); - sEmitInfo->SetNextFieldOffset(sEmitInfo->GetTotalSize() * charBitWidth); - } - } - fieldIdx++; - } - if (structType.GetKind() == kTypeStruct) { - /* The reason of subtracting one is that fieldIdx adds one at the end of the cycle. */ - DEBUG_ASSERT(fieldIdx > 0, "must not be zero"); - subStructFieldCounts = fieldIdx - 1; - } else if (structType.GetKind() == kTypeUnion) { - subStructFieldCounts = static_cast(beCommon->GetStructFieldCount(structType.GetTypeIndex())); - } - - uint64 opSize = sizeInByte - sEmitInfo->GetTotalSize(); - if (opSize != 0) { - assmbler.EmitNull(opSize); - } -#endif - return valueSize; -} - uint64 X64Emitter::EmitArray(MIRConst &mirConst, CG &cg, bool belongsToDataSec) { uint64 valueSize = 0; @@ -1680,9 +1581,6 @@ uint64 X64Emitter::EmitArray(MIRConst &mirConst, CG &cg, bool belongsToDataSec) } } else if (elemConst->GetType().GetKind() == kTypeArray) { valueSize += EmitArray(*elemConst, cg, belongsToDataSec); - } else if (elemConst->GetType().GetKind() == kTypeStruct || elemConst->GetType().GetKind() == kTypeClass || - elemConst->GetType().GetKind() == kTypeUnion) { - valueSize += EmitStructure(*elemConst, cg); } else if (elemConst->GetKind() == kConstAddrofFunc) { valueSize += EmitSingleElement(*elemConst, belongsToDataSec); } else { @@ -1730,11 +1628,6 @@ void X64Emitter::EmitAddrofElement(MIRConst &mirConst, bool belongsToDataSec) if (symAddr.GetOffset() != 0) { symAddrOfs = symAddr.GetOffset(); } - if (symAddr.GetFieldID() > 1) { - MIRStructType *structType = static_cast(symAddrSym->GetType()); - DEBUG_ASSERT(structType != nullptr, "EmitScalarConstant: non-zero fieldID for non-structure"); - structFieldOfs = Globals::GetInstance()->GetBECommon()->GetFieldOffset(*structType, symAddr.GetFieldID()).first; - } assmbler.StoreNameIntoSymMap(symIdx, addrName); assmbler.EmitAddrValue(symIdx, symAddrOfs, structFieldOfs, belongsToDataSec); #endif @@ -1939,9 +1832,7 @@ void X64Emitter::EmitLocalVariable(CGFunc &cgFunc) (ct->GetKind() == maple::kConstDoubleConst || ct->GetKind() == maple::kConstFloatConst); auto secType = isFloatTy ? kSText : kSData; assmbler.EmitVariable(symIdx, sizeInByte, alignInByte, kSALocal, secType); - if (kind == kTypeStruct || kind == kTypeUnion || kind == kTypeClass) { - valueSize = EmitStructure(*ct, *cgFunc.GetCG()); - } else if (kind == kTypeArray) { + if (kind == kTypeArray) { valueSize = EmitArray(*ct, *cgFunc.GetCG()); } else if (isFloatTy) { MIRType &elmType = ct->GetType(); @@ -2033,9 +1924,6 @@ void X64Emitter::EmitGlobalVariable(CG &cg) } else if (kind == kTypeArray) { CHECK_FATAL(!mirSymbol->HasAddrOfValues(), "EmitGlobalVariable: need EmitConstantTable"); valueSize = EmitArray(*mirConst, cg); - } else if (kind == kTypeStruct || kind == kTypeClass || kind == kTypeUnion) { - CHECK_FATAL(!mirSymbol->HasAddrOfValues(), "EmitGlobalVariable: need EmitConstantTable"); - EmitStructure(*mirConst, cg); } else { DEBUG_ASSERT(false, "EmitGlobalVariable: Unknown mirKind"); } @@ -2063,8 +1951,6 @@ void X64Emitter::EmitGlobalVariable(CG &cg) } } else if (kind == kTypeArray) { (void)EmitArray(*mirConst, cg, false); - } else if (kind == kTypeStruct || kind == kTypeUnion || kind == kTypeClass) { - (void)EmitStructure(*mirConst, cg); } else { FATAL(kLncFatal, "Unknown type in Global pstatic"); } diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_memlayout.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_memlayout.cpp index 388da7a706..536b24c451 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_memlayout.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/cg/x86_64/x64_memlayout.cpp @@ -48,32 +48,12 @@ uint32 X64MemLayout::ComputeStackSpaceRequirementForCall(StmtNode &stmt, int32 & CHECK_NULL_FATAL(be.GetMIRModule().CurFunction()); MIRSymbol *sym = be.GetMIRModule().CurFunction()->GetLocalOrGlobalSymbol(dread->GetStIdx()); ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(sym->GetTyIdx()); - if (dread->GetFieldID() != 0) { - DEBUG_ASSERT(ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeClass || - ty->GetKind() == kTypeUnion, - "expect struct or class"); - if (ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeUnion) { - ty = static_cast(ty)->GetFieldType(dread->GetFieldID()); - } else { - ty = static_cast(ty)->GetFieldType(dread->GetFieldID()); - } - } } else { /* OP_iread */ IreadNode *iread = static_cast(opnd); ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(iread->GetTyIdx()); DEBUG_ASSERT(ty->GetKind() == kTypePointer, "expect pointer"); ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(static_cast(ty)->GetPointedTyIdx()); - if (iread->GetFieldID() != 0) { - DEBUG_ASSERT(ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeClass || - ty->GetKind() == kTypeUnion, - "expect struct or class"); - if (ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeUnion) { - ty = static_cast(ty)->GetFieldType(iread->GetFieldID()); - } else { - ty = static_cast(ty)->GetFieldType(iread->GetFieldID()); - } - } } } CCLocInfo ploc; diff --git a/ecmascript/compiler/codegen/maple/maple_be/src/litecg/lmir_builder.cpp b/ecmascript/compiler/codegen/maple/maple_be/src/litecg/lmir_builder.cpp index 358b7b0b2b..fb65530566 100644 --- a/ecmascript/compiler/codegen/maple/maple_be/src/litecg/lmir_builder.cpp +++ b/ecmascript/compiler/codegen/maple/maple_be/src/litecg/lmir_builder.cpp @@ -98,10 +98,6 @@ LiteCGTypeKind LMIRBuilder::LiteCGGetTypeKind(Type *type) const return kLiteCGTypeFArray; case MIRTypeKind::kTypeJArray: return kLiteCGTypeJArray; - case MIRTypeKind::kTypeStruct: - return kLiteCGTypeStruct; - case MIRTypeKind::kTypeUnion: - return kLiteCGTypeUnion; case MIRTypeKind::kTypeClass: return kLiteCGTypeClass; case MIRTypeKind::kTypeInterface: @@ -170,33 +166,6 @@ bool LMIRBuilder::IsHeapPointerType(Type *mirType) const return mirType->GetPrimType() == PTY_ref; } -Type *LMIRBuilder::CreateStructTypeInternal(const String &name, - std::vector> &fields_) -{ - FieldVector parentFields; // parentFields not used. - // not sure about the cost - FieldVector fields; - for (auto field : fields_) { - auto strIdx = mirBuilder.GetOrCreateStringIndex(field.first.data()); - fields.push_back(FieldPair(strIdx, TyIdxFieldAttrPair(field.second->GetTypeIndex(), FieldAttrs()))); - } - auto type = GlobalTables::GetTypeTable().GetOrCreateStructType(name, fields, parentFields, module); - return type; -} - -Type *LMIRBuilder::GetStructType(const String &name) -{ - GStrIdx strIdx = GlobalTables::GetStrTable().GetStrIdxFromName(name); - TyIdx typeIdx = GlobalTables::GetTypeNameTable().GetTyIdxFromGStrIdx(strIdx); - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(typeIdx); - return type; -} - -StructConst &LMIRBuilder::CreateStructConstInternal(StructType *type) -{ - return *module.GetMemPool()->New(module, *type); -} - ArrayConst &LMIRBuilder::CreateArrayConstInternal(ArrayType *type) { return *module.GetMemPool()->New(module, *type); @@ -601,14 +570,6 @@ Expr LMIRBuilder::IntrinsicOp(IntrinsicId id, Type *type, Args &args_) return Expr(mirBuilder.CreateExprIntrinsicop(func, OP_intrinsicop, *type, args), type); } -Expr LMIRBuilder::DreadWithField(Var &var, FieldId id) -{ - auto *type = var.GetType(); - CHECK_FATAL(type->IsStructType(), "DreadWithField: must be a struct type!"); - auto *fldType = static_cast(type)->GetFieldType(id); - return Expr(mirBuilder.CreateExprDread(*fldType, id, var), fldType); -} - Expr LMIRBuilder::Iread(Type *type, Expr addr, Type *baseType, FieldId fieldId) { return Expr(mirBuilder.CreateExprIread(*type, *baseType, fieldId, addr.GetNode()), type); diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/global_tables.h b/ecmascript/compiler/codegen/maple/maple_ir/include/global_tables.h index 3ec51e2895..03db1944d6 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/global_tables.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/global_tables.h @@ -345,30 +345,8 @@ public: MIRType *GetOrCreateJarrayType(const MIRType &elem); MIRType *GetOrCreateFunctionType(const TyIdx &, const std::vector &, const std::vector &, bool isVarg = false, const TypeAttrs &retAttrs = TypeAttrs()); - MIRType *GetOrCreateStructType(const std::string &name, const FieldVector &fields, const FieldVector &prntFields, - MIRModule &module) - { - return GetOrCreateStructOrUnion(name, fields, prntFields, module); - } - - MIRType *GetOrCreateUnionType(const std::string &name, const FieldVector &fields, const FieldVector &parentFields, - MIRModule &module) - { - return GetOrCreateStructOrUnion(name, fields, parentFields, module, false); - } - - MIRType *GetOrCreateClassType(const std::string &name, MIRModule &module) - { - return GetOrCreateClassOrInterface(name, module, true); - } - - MIRType *GetOrCreateInterfaceType(const std::string &name, MIRModule &module) - { - return GetOrCreateClassOrInterface(name, module, false); - } void PushIntoFieldVector(FieldVector &fields, const std::string &name, const MIRType &type); - void AddFieldToStructType(MIRStructType &structType, const std::string &fieldName, const MIRType &fieldType); TyIdx lastDefaultTyIdx; @@ -408,10 +386,6 @@ private: void CreateMirTypeNodeAt(MIRType &pType, TyIdx tyIdxUsed, MIRModule *module, bool isObject, bool isIncomplete); MIRType *CreateAndUpdateMirTypeNode(MIRType &pType); - MIRType *GetOrCreateStructOrUnion(const std::string &name, const FieldVector &fields, - const FieldVector &printFields, MIRModule &module, bool forStruct = true, - const TypeAttrs &attrs = TypeAttrs()); - MIRType *GetOrCreateClassOrInterface(const std::string &name, MIRModule &module, bool forClass); MIRType *CreateMirType(uint32 primTypeIdx) const; void PutToHashTable(MIRType *mirType); diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/intrinsics.h b/ecmascript/compiler/codegen/maple/maple_ir/include/intrinsics.h index fd64edfe44..446ecc3045 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/intrinsics.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/intrinsics.h @@ -155,7 +155,6 @@ struct IntrinDesc { static MIRType *jsValueType; static MIRModule *mirModule; static void InitMIRModule(MIRModule *mirModule); - static MIRType *GetOrCreateJSValueType(); static IntrinDesc intrinTable[INTRN_LAST + 1]; }; } // namespace maple diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/ir_safe_cast_traits.def b/ecmascript/compiler/codegen/maple/maple_ir/include/ir_safe_cast_traits.def index 699fc5dcb6..b08ac1a3f6 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/ir_safe_cast_traits.def +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/ir_safe_cast_traits.def @@ -38,16 +38,7 @@ REGISTER_SAFE_CAST(MIRPtrType, from.GetKind() == kTypePointer); REGISTER_SAFE_CAST(MIRArrayType, from.GetKind() == kTypeArray); REGISTER_SAFE_CAST(MIRFarrayType, from.GetKind() == kTypeFArray || instance_of(from)); -REGISTER_SAFE_CAST(MIRStructType, from.GetKind() == kTypeStruct || - from.GetKind() == kTypeStructIncomplete || - from.GetKind() == kTypeUnion || - instance_of(from) || - instance_of(from)); REGISTER_SAFE_CAST(MIRJarrayType, from.GetKind() == kTypeJArray); -REGISTER_SAFE_CAST(MIRClassType, from.GetKind() == kTypeClass || - from.GetKind() == kTypeClassIncomplete); -REGISTER_SAFE_CAST(MIRInterfaceType, from.GetKind() == kTypeInterface || - from.GetKind() == kTypeInterfaceIncomplete); REGISTER_SAFE_CAST(MIRBitFieldType, from.GetKind() == kTypeBitField); REGISTER_SAFE_CAST(MIRFuncType, from.GetKind() == kTypeFunction); REGISTER_SAFE_CAST(MIRTypeByName, from.GetKind() == kTypeByName); diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_builder.h b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_builder.h index d42e2499c3..4867d36984 100755 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_builder.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_builder.h @@ -116,29 +116,7 @@ public: MIRFunction *GetOrCreateFunction(const std::string &, TyIdx); MIRFunction *GetFunctionFromSymbol(const MIRSymbol &funcst); MIRFunction *GetFunctionFromName(const std::string &); - // For compiler-generated metadata struct - void AddIntFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, int64 constValue); - void AddAddrofFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, - const MIRSymbol &fieldSt); - void AddAddroffuncFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, - const MIRSymbol &funcSt); - bool TraverseToNamedField(MIRStructType &structType, GStrIdx nameIdx, uint32 &fieldID); - bool TraverseToNamedFieldWithTypeAndMatchStyle(MIRStructType &structType, GStrIdx nameIdx, TyIdx typeIdx, - uint32 &fieldID, unsigned int matchStyle); - void TraverseToNamedFieldWithType(MIRStructType &structType, GStrIdx nameIdx, TyIdx typeIdx, uint32 &fieldID, - uint32 &idx); - - FieldID GetStructFieldIDFromNameAndType(MIRType &type, const std::string &name, TyIdx idx, unsigned int matchStyle); - FieldID GetStructFieldIDFromNameAndType(MIRType &type, const std::string &name, TyIdx idx); - FieldID GetStructFieldIDFromNameAndTypeParentFirst(MIRType &type, const std::string &name, TyIdx idx); - FieldID GetStructFieldIDFromNameAndTypeParentFirstFoundInChild(MIRType &type, const std::string &name, TyIdx idx); - - FieldID GetStructFieldIDFromFieldName(MIRType &type, const std::string &name); - FieldID GetStructFieldIDFromFieldNameParentFirst(MIRType *type, const std::string &name); - - void SetStructFieldIDFromFieldName(MIRStructType &structType, const std::string &name, GStrIdx newStrIdx, - const MIRType &newFieldType); // for creating Function. MIRSymbol *GetFunctionArgument(MIRFunction &fun, uint32 index) const { diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_function.h b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_function.h index c14248083c..f418f4e883 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_function.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_function.h @@ -478,10 +478,6 @@ public: bool HasCall() const; void SetHasCall(); - bool IsReturnStruct() const; - void SetReturnStruct(); - void SetReturnStruct(const MIRType &retType); - bool IsUserFunc() const; void SetUserFunc(); @@ -498,11 +494,6 @@ public: void SetHasAsm(); bool HasAsm() const; - void SetStructReturnedInRegs(); - bool StructReturnedInRegs() const; - - void SetReturnStruct(const MIRType *retType); - bool IsEmpty() const; bool IsClinit() const; uint32 GetInfo(GStrIdx strIdx) const; @@ -615,17 +606,6 @@ public: return codeMemPoolAllocator; } - TyIdx GetFuncRetStructTyIdx() - { - TyIdx tyIdx = GetFormalDefAt(0).formalTyIdx; - MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - CHECK_FATAL(ty->GetKind() == kTypePointer, "Fake param not a pointer"); - MIRPtrType *pType = static_cast(ty); - tyIdx = pType->GetPointedTyIdx(); - CHECK_FATAL(GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)->IsStructType(), "Must be struct return type"); - return tyIdx; - } - void EnterFormals(); void NewBody(); 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 a531c3b21f..18861bf7b9 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_module.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_module.h @@ -317,7 +317,6 @@ public: #endif const std::string &GetFileNameFromFileNum(uint32 fileNum) const; #ifdef ARK_LITECG_DEBUG - void DumpToCxxHeaderFile(std::set &leafClasses, const std::string &pathToOutf) const; void DumpClassToFile(const std::string &path) const; void DumpFunctionList(const std::unordered_set *dumpFuncSet) const; void DumpGlobalArraySymbol() const; @@ -822,10 +821,6 @@ public: bool HasNotWarned(uint32 postion, uint32 stmtOriginalID); private: -#ifdef ARK_LITECG_DEBUG - void DumpTypeTreeToCxxHeaderFile(MIRType &ty, std::unordered_set &dumpedClasses) const; -#endif - MemPool *memPool; MemPool *pragmaMemPool; MapleAllocator memPoolAllocator; diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_nodes.h b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_nodes.h index 8b265b8fe5..e23984b0ad 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_nodes.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_nodes.h @@ -356,11 +356,6 @@ private: return from.IsMIRPtrType() || from.IsMIRJarrayType(); } - bool IsInterfaceOrClass(const MIRType &mirType) const - { - return mirType.IsMIRClassType() || mirType.IsMIRInterfaceType(); - } - TyIdx tyIdx = TyIdx(0); }; @@ -1201,8 +1196,6 @@ public: void Dump(int32 indent) const override; #endif - bool CheckNode(const MIRModule &mod) const; - AddrofNode *CloneTree(MapleAllocator &allocator) const override { return allocator.GetMemPool()->New(*this); 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 b98d266734..6a18c0300b 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_symbol.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_symbol.h @@ -572,25 +572,12 @@ public: { uint8 align = GetAttrs().GetAlignValue(); if (align == 0) { - 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) { - return align; - } - uint8 alignMin = 0; - if (GetType()->GetAlign() > 0) { - alignMin = static_cast(log2(GetType()->GetAlign())); - } - align = std::max(3, alignMin); // 3: alignment in bytes of uint8 - } else { - align = static_cast(GetType()->GetAlign()); - if (Triple::GetTriple().IsAarch64BeOrLe()) { - if (isArm64ilp32 && GetType()->GetPrimType() == PTY_a32) { - align = 3; // 3: alignment in bytes of uint8 - } else { - align = static_cast(log2(align)); - } + align = static_cast(GetType()->GetAlign()); + if (Triple::GetTriple().IsAarch64BeOrLe()) { + if (isArm64ilp32 && GetType()->GetPrimType() == PTY_a32) { + align = 3; // 3: alignment in bytes of uint8 + } else { + align = static_cast(log2(align)); } } } diff --git a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_type.h b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_type.h index b5f595e502..8d61dc8374 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/include/mir_type.h +++ b/ecmascript/compiler/codegen/maple/maple_ir/include/mir_type.h @@ -183,8 +183,6 @@ enum MIRTypeKind : std::uint8_t { kTypeArray, kTypeFArray, kTypeJArray, - kTypeStruct, - kTypeUnion, kTypeClass, kTypeInterface, kTypeStructIncomplete, @@ -815,8 +813,6 @@ struct OffsetType { int32 val = kOffsetUnknown; }; - -class MIRStructType; // circular dependency exists, no other choice class MIRFuncType; // if it is a bitfield, byteoffset gives the offset of the container for @@ -938,31 +934,11 @@ public: return typeKind == kTypePointer; } - bool IsMIRStructType() const - { - return (typeKind == kTypeStruct) || (typeKind == kTypeStructIncomplete); - } - - bool IsMIRUnionType() const - { - return typeKind == kTypeUnion; - } - - bool IsMIRClassType() const - { - return (typeKind == kTypeClass) || (typeKind == kTypeClassIncomplete); - } - bool IsMIRInterfaceType() const { return (typeKind == kTypeInterface) || (typeKind == kTypeInterfaceIncomplete); } - bool IsInstanceOfMIRStructType() const - { - return IsMIRStructType() || IsMIRClassType() || IsMIRInterfaceType(); - } - bool IsMIRJarrayType() const { return typeKind == kTypeJArray; @@ -1023,11 +999,6 @@ public: { return 0; } - // return any struct type directly embedded in this type - virtual MIRStructType *EmbeddedStructType() - { - return nullptr; - } virtual int64 GetBitOffsetFromBaseAddr(FieldID fieldID) { @@ -1095,8 +1066,6 @@ public: #endif size_t GetSize() const override; uint32 GetAlign() const override; - TyIdxFieldAttrPair GetPointedTyIdxFldAttrPairWithFieldID(FieldID fldId) const; - TyIdx GetPointedTyIdxWithFieldID(FieldID fieldID) const; size_t GetHashIndex() const override { constexpr uint8 idxShift = 4; @@ -1240,7 +1209,6 @@ public: std::string GetCompactMplTypeName() const override; bool HasFields() const override; uint32 NumberOfFieldIDs() const override; - MIRStructType *EmbeddedStructType() override; size_t ElemNumber() const; private: @@ -1299,7 +1267,6 @@ public: bool HasFields() const override; uint32 NumberOfFieldIDs() const override; - MIRStructType *EmbeddedStructType() override; int64 GetBitOffsetFromBaseAddr(FieldID fieldID) override { @@ -1323,512 +1290,6 @@ class GenericDeclare; class AnnotationType; class GenericType; // used by kTypeStruct, kTypeStructIncomplete, kTypeUnion -class MIRStructType : public MIRType { -public: - explicit MIRStructType(MIRTypeKind typeKind) : MIRType(typeKind, PTY_agg) {} - - MIRStructType(MIRTypeKind typeKind, GStrIdx strIdx) : MIRType(typeKind, PTY_agg, strIdx) {} - - ~MIRStructType() override = default; - - bool IsStructType() const override - { - return true; - } - - FieldVector &GetFields() - { - return fields; - } - const FieldVector &GetFields() const - { - return fields; - } - void SetFields(const FieldVector &newFields) - { - this->fields = newFields; - } - - const FieldPair &GetFieldsElemt(size_t n) const - { - DEBUG_ASSERT(n < fields.size(), "array index out of range"); - return fields.at(n); - } - - FieldPair &GetFieldsElemt(size_t n) - { - DEBUG_ASSERT(n < fields.size(), "array index out of range"); - return fields.at(n); - } - - size_t GetFieldsSize() const - { - return fields.size(); - } - - const std::vector &GetFieldInferredTyIdx() const - { - return fieldInferredTyIdx; - } - - FieldVector &GetStaticFields() - { - return staticFields; - } - const FieldVector &GetStaticFields() const - { - return staticFields; - } - - const FieldPair &GetStaticFieldsPair(size_t i) const - { - return staticFields.at(i); - } - - GStrIdx GetStaticFieldsGStrIdx(size_t i) const - { - return staticFields.at(i).first; - } - - FieldVector &GetParentFields() - { - return parentFields; - } - void SetParentFields(const FieldVector &newParentFields) - { - this->parentFields = newParentFields; - } - const FieldVector &GetParentFields() const - { - return parentFields; - } - const FieldPair &GetParentFieldsElemt(size_t n) const - { - DEBUG_ASSERT(n < parentFields.size(), "array index out of range"); - return parentFields.at(n); - } - size_t GetParentFieldsSize() const - { - return parentFields.size(); - } - - MethodVector &GetMethods() - { - return methods; - } - const MethodVector &GetMethods() const - { - return methods; - } - - const MethodPair &GetMethodsElement(size_t n) const - { - DEBUG_ASSERT(n < methods.size(), "array index out of range"); - return methods.at(n); - } - - MethodPtrVector &GetVTableMethods() - { - return vTableMethods; - } - - const MethodPair *GetVTableMethodsElemt(size_t n) const - { - DEBUG_ASSERT(n < vTableMethods.size(), "array index out of range"); - return vTableMethods.at(n); - } - - size_t GetVTableMethodsSize() const - { - return vTableMethods.size(); - } - - const MethodPtrVector &GetItableMethods() const - { - return iTableMethods; - } - - bool IsImported() const - { - return isImported; - } - - void SetIsImported(bool flag) - { - isImported = flag; - } - - bool IsUsed() const - { - return isUsed; - } - - void SetIsUsed(bool flag) - { - isUsed = flag; - } - - bool IsCPlusPlus() const - { - return isCPlusPlus; - } - - void SetIsCPlusPlus(bool flag) - { - isCPlusPlus = flag; - } - - GStrIdx GetFieldGStrIdx(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.first; - } - - const TyIdxFieldAttrPair GetFieldTyIdxAttrPair(FieldID id) const - { - return TraverseToField(id).second; - } - - TyIdxFieldAttrPair GetTyidxFieldAttrPair(size_t n) const - { - return fields.at(n).second; - } - - TyIdx GetFieldTyIdx(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.second.first; - } - - FieldAttrs GetFieldAttrs(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.second.second; - } - - FieldAttrs GetFieldAttrs(GStrIdx fieldStrIdx) const - { - const FieldPair &fieldPair = TraverseToField(fieldStrIdx); - return fieldPair.second.second; - } - - bool IsFieldVolatile(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.second.second.GetAttr(FLDATTR_volatile); - } - - bool IsFieldFinal(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.second.second.GetAttr(FLDATTR_final); - } - - bool IsFieldRCUnownedRef(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.second.second.GetAttr(FLDATTR_rcunowned); - } - - bool IsFieldRCWeak(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.second.second.GetAttr(FLDATTR_rcweak); - } - - bool IsFieldRestrict(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return fieldPair.second.second.GetAttr(FLDATTR_restrict); - } - - bool IsOwnField(FieldID id) const - { - const FieldPair &fieldPair = TraverseToField(id); - return std::find(fields.begin(), fields.end(), fieldPair) != fields.end(); - } - - TypeAttrs &GetTypeAttrs() - { - return typeAttrs; - } - - const TypeAttrs &GetTypeAttrs() const - { - return typeAttrs; - } - - void SetTypeAttrs(const TypeAttrs &attrs) - { - typeAttrs = attrs; - } - - bool HasVolatileField() const override; - bool HasTypeParam() const override; - bool EqualTo(const MIRType &type) const override; - MIRType *CopyMIRTypeNode() const override - { - return new MIRStructType(*this); - } - - TyIdx GetElemTyIdx(size_t n) const - { - DEBUG_ASSERT(n < fields.size(), "array index out of range"); - return fields.at(n).second.first; - } - - void SetElemtTyIdxSimple(size_t n, TyIdx tyIdx) - { - DEBUG_ASSERT(n < fields.size(), "array index out of range"); - fields.at(n).second.first = tyIdx; - } - - TyIdx GetStaticElemtTyIdx(size_t n) const - { - DEBUG_ASSERT(n < staticFields.size(), "array index out of range"); - return staticFields.at(n).second.first; - } - - void SetStaticElemtTyIdx(size_t n, TyIdx tyIdx) - { - staticFields.at(n).second.first = tyIdx; - } - - void SetMethodTyIdx(size_t n, TyIdx tyIdx) - { - DEBUG_ASSERT(n < methods.size(), "array index out of range"); - methods.at(n).second.first = tyIdx; - } - - MIRType *GetElemType(uint32 n) const; - - MIRType *GetFieldType(FieldID fieldID); - - void SetElemtTyIdx(size_t n, TyIdx tyIdx) - { - DEBUG_ASSERT(n < fields.size(), "array index out of range"); - fields.at(n).second = TyIdxFieldAttrPair(tyIdx, FieldAttrs()); - } - - GStrIdx GetElemStrIdx(size_t n) const - { - DEBUG_ASSERT(n < fields.size(), "array index out of range"); - return fields.at(n).first; - } - - void SetElemStrIdx(size_t n, GStrIdx idx) - { - DEBUG_ASSERT(n < fields.size(), "array index out of range"); - fields.at(n).first = idx; - } - - void SetElemInferredTyIdx(size_t n, TyIdx tyIdx) - { - if (n >= fieldInferredTyIdx.size()) { - (void)fieldInferredTyIdx.insert(fieldInferredTyIdx.end(), n + 1 - fieldInferredTyIdx.size(), kInitTyIdx); - } - DEBUG_ASSERT(n < fieldInferredTyIdx.size(), "array index out of range"); - fieldInferredTyIdx.at(n) = tyIdx; - } - - TyIdx GetElemInferredTyIdx(size_t n) - { - if (n >= fieldInferredTyIdx.size()) { - (void)fieldInferredTyIdx.insert(fieldInferredTyIdx.end(), n + 1 - fieldInferredTyIdx.size(), kInitTyIdx); - } - DEBUG_ASSERT(n < fieldInferredTyIdx.size(), "array index out of range"); - return fieldInferredTyIdx.at(n); - } -#ifdef ARK_LITECG_DEBUG - void DumpFieldsAndMethods(int indent, bool hasMethod) const; - void Dump(int indent, bool dontUseName = false) const override; -#endif - virtual void SetComplete() - { - typeKind = (typeKind == kTypeUnion) ? typeKind : kTypeStruct; - } - - // only meaningful for MIRClassType and MIRInterface types - bool IsLocal() const; - - size_t GetSize() const override; - uint32 GetTypedefOriginalAlign() const; - uint32 GetAlign() const override; - uint32 GetAlignAux(bool toGetOriginal) const; - uint32 GetUnadjustedAlign() const override; - - size_t GetHashIndex() const override - { - constexpr uint8 attrShift = 3; - return ((static_cast(nameStrIdx) << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind) + - ((typeAttrs.GetAttrFlag() << attrShift) + typeAttrs.GetAlignValue())) % - kTypeHashLength; - } - - virtual void ClearContents() - { - fields.clear(); - staticFields.clear(); - parentFields.clear(); - methods.clear(); - vTableMethods.clear(); - iTableMethods.clear(); - isImported = false; - isUsed = false; - hasVolatileField = false; - hasVolatileFieldSet = false; - } - - virtual const std::vector &GetInfo() const - { - CHECK_FATAL(false, "can not use GetInfo"); - } - - virtual const MIRInfoPair &GetInfoElemt(size_t) const - { - CHECK_FATAL(false, "can not use GetInfoElemt"); - } - - virtual const std::vector &GetInfoIsString() const - { - CHECK_FATAL(false, "can not use GetInfoIsString"); - } - - virtual bool GetInfoIsStringElemt(size_t) const - { - CHECK_FATAL(false, "can not use GetInfoIsStringElemt"); - } - - std::vector &GetGenericDeclare() - { - return genericDeclare; - } - - void AddClassGenericDeclare(GenericDeclare *gd) - { - genericDeclare.push_back(gd); - } - - void AddFieldGenericDeclare(const GStrIdx &g, AnnotationType *a) - { - if (fieldGenericDeclare.find(g) != fieldGenericDeclare.end()) { - CHECK_FATAL(fieldGenericDeclare[g] == a, "MUST BE"); - } - fieldGenericDeclare[g] = a; - } - - AnnotationType *GetFieldGenericDeclare(const GStrIdx &g) - { - if (fieldGenericDeclare.find(g) == fieldGenericDeclare.end()) { - return nullptr; - } - return fieldGenericDeclare[g]; - } - - void AddInheritaceGeneric(GenericType *a) - { - inheritanceGeneric.push_back(a); - } - - std::vector &GetInheritanceGeneric() - { - return inheritanceGeneric; - } - - virtual const MIREncodedArray &GetStaticValue() const - { - CHECK_FATAL(false, "can not use GetStaticValue"); - } - - virtual void PushbackMIRInfo(const MIRInfoPair &) - { - CHECK_FATAL(false, "can not use PushbackMIRInfo"); - } - - virtual void PushbackStaticValue(EncodedValue &) - { - CHECK_FATAL(false, "can not use PushbackStaticValue"); - } - - virtual void PushbackIsString(bool) - { - CHECK_FATAL(false, "can not use PushbackIsString"); - } - - bool HasFields() const override - { - return true; - } - uint32 NumberOfFieldIDs() const override; - MIRStructType *EmbeddedStructType() override - { - return this; - } - - virtual FieldPair TraverseToFieldRef(FieldID &fieldID) const; - std::string GetMplTypeName() const override; - std::string GetCompactMplTypeName() const override; - FieldPair TraverseToField(FieldID fieldID) const; - - int64 GetBitOffsetFromBaseAddr(FieldID fieldID) override; - - FieldInfo GetFieldOffsetFromBaseAddr(FieldID fieldID) const; - - bool HasPadding() const; - - bool HasZeroWidthBitField() const; - - void AddFieldLayout(const FieldInfo &info) - { - fieldLayout.emplace_back(info); - } - - std::vector &GetFieldLayout() - { - if (!layoutComputed) { - ComputeLayout(); - } - return fieldLayout; - } - - uint32 GetFieldTypeAlignByFieldPair(const FieldPair &fieldPair); - -protected: - FieldVector fields {}; - std::vector fieldInferredTyIdx {}; - FieldVector staticFields {}; - FieldVector parentFields {}; // fields belong to the ancestors not fully defined - MethodVector methods {}; // for the list of member function prototypes - MethodPtrVector vTableMethods {}; // the list of implmentation for all virtual functions for this type - MethodPtrVector iTableMethods {}; // the list of all interface functions for this type; For classes, they are - // implementation functions, For interfaces, they are abstact functions. - // Weak indicates the actual definition is in another module. - bool isImported = false; - bool isUsed = false; - bool isCPlusPlus = false; // empty struct in C++ has size 1 byte - mutable bool hasVolatileField = false; // for caching computed value - mutable bool hasVolatileFieldSet = false; // if true, just read hasVolatileField; - // otherwise compute to initialize hasVolatileField - std::vector genericDeclare; - std::map fieldGenericDeclare; - std::vector inheritanceGeneric; - TypeAttrs typeAttrs; - mutable uint32 fieldsNum = kInvalidFieldNum; - mutable std::vector fieldLayout; - mutable size_t size = kInvalidSize; - - bool layoutComputed = false; - -private: - FieldPair TraverseToField(GStrIdx fieldStrIdx) const; - bool HasVolatileFieldInFields(const FieldVector &fieldsOfStruct) const; - bool HasTypeParamInFields(const FieldVector &fieldsOfStruct) const; - int64 GetBitOffsetFromUnionBaseAddr(FieldID fieldID); - int64 GetBitOffsetFromStructBaseAddr(FieldID fieldID); - void ComputeUnionLayout(); - void ComputeLayout(); -}; - class MIRJarrayType : public MIRFarrayType { public: MIRJarrayType() @@ -1853,16 +1314,6 @@ public: return new MIRJarrayType(*this); } - MIRStructType *GetParentType(); - - bool IsPrimitiveArray() - { - if (jNameStrIdx == 0u) { - DetermineName(); - } - return fromPrimitive; - } - int GetDim() { if (jNameStrIdx == 0u) { @@ -1882,300 +1333,10 @@ private: void DetermineName(); // determine the internal name of this type TyIdx parentTyIdx {0}; // since Jarray is also an object, this is j.lang.Object GStrIdx jNameStrIdx {0}; // for internal j name of Jarray. nameStrIdx is used for other purpose - bool fromPrimitive = false; // the lowest dimension is primitive type int dim = 0; // the dimension if decidable at compile time. otherwise 0 }; // used by kTypeClass, kTypeClassIncomplete -class MIRClassType : public MIRStructType { -public: - explicit MIRClassType(MIRTypeKind tKind) : MIRStructType(tKind) {} - MIRClassType(MIRTypeKind tKind, GStrIdx strIdx) : MIRStructType(tKind, strIdx) {} - ~MIRClassType() override = default; - - bool EqualTo(const MIRType &type) const override; - - MIRType *CopyMIRTypeNode() const override - { - return new MIRClassType(*this); - } - - const std::vector &GetInfo() const override - { - return info; - } - void PushbackMIRInfo(const MIRInfoPair &pair) override - { - info.push_back(pair); - } - uint32 GetInfo(const std::string &infoStr) const; - uint32 GetInfo(GStrIdx strIdx) const; - size_t GetInfoSize() const - { - return info.size(); - } - - const MIRInfoPair &GetInfoElemt(size_t n) const override - { - DEBUG_ASSERT(n < info.size(), "array index out of range"); - return info.at(n); - } - - const std::vector &GetInfoIsString() const override - { - return infoIsString; - } - - void PushbackIsString(bool isString) override - { - infoIsString.push_back(isString); - } - - size_t GetInfoIsStringSize() const - { - return infoIsString.size(); - } - - bool GetInfoIsStringElemt(size_t n) const override - { - DEBUG_ASSERT(n < infoIsString.size(), "array index out of range"); - return infoIsString.at(n); - } - - const MIREncodedArray &GetStaticValue() const override - { - return staticValue; - } - void PushbackStaticValue(EncodedValue &encodedValue) override - { - staticValue.push_back(encodedValue); - } - - TyIdx GetParentTyIdx() const - { - return parentTyIdx; - } - void SetParentTyIdx(TyIdx idx) - { - parentTyIdx = idx; - } - - std::vector &GetInterfaceImplemented() - { - return interfacesImplemented; - } - const std::vector &GetInterfaceImplemented() const - { - return interfacesImplemented; - } - TyIdx GetNthInterfaceImplemented(size_t i) const - { - DEBUG_ASSERT(i < interfacesImplemented.size(), "array index out of range"); - return interfacesImplemented.at(i); - } - - void SetNthInterfaceImplemented(size_t i, TyIdx tyIdx) - { - DEBUG_ASSERT(i < interfacesImplemented.size(), "array index out of range"); - interfacesImplemented.at(i) = tyIdx; - } - void PushbackInterfaceImplemented(TyIdx idx) - { - interfacesImplemented.push_back(idx); - } -#ifdef ARK_LITECG_DEBUG - void Dump(int indent, bool dontUseName = false) const override; - void DumpAsCxx(int indent) const override; -#endif - void SetComplete() override - { - typeKind = kTypeClass; - } - - bool IsFinal() const; - bool IsAbstract() const; - bool IsInner() const; - bool HasVolatileField() const override; - bool HasTypeParam() const override; - FieldPair TraverseToFieldRef(FieldID &fieldID) const override; - size_t GetSize() const override; - - FieldID GetLastFieldID() const; - FieldID GetFirstFieldID() const - { - return GetLastFieldID() - fields.size() + 1; - } - - FieldID GetFirstLocalFieldID() const; - // return class id or superclass id accroding to input string - void AddImplementedInterface(TyIdx interfaceTyIdx) - { - if (std::find(interfacesImplemented.begin(), interfacesImplemented.end(), interfaceTyIdx) == - interfacesImplemented.end()) { - interfacesImplemented.push_back(interfaceTyIdx); - } - } - - void ClearContents() override - { - MIRStructType::ClearContents(); - parentTyIdx = TyIdx(0); - interfacesImplemented.clear(); // for the list of interfaces the class implements - info.clear(); - infoIsString.clear(); - staticValue.clear(); - } - - size_t GetHashIndex() const override - { - return ((static_cast(nameStrIdx) << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % - kTypeHashLength; - } - - uint32 NumberOfFieldIDs() const override; - -private: - TyIdx parentTyIdx {0}; - std::vector interfacesImplemented {}; // for the list of interfaces the class implements - std::vector info {}; - std::vector infoIsString {}; - MIREncodedArray staticValue {}; // DELETE THIS -}; - -// used by kTypeInterface, kTypeInterfaceIncomplete -class MIRInterfaceType : public MIRStructType { -public: - explicit MIRInterfaceType(MIRTypeKind tKind) : MIRStructType(tKind) {} - MIRInterfaceType(MIRTypeKind tKind, GStrIdx strIdx) : MIRStructType(tKind, strIdx) {} - ~MIRInterfaceType() override = default; - - bool EqualTo(const MIRType &type) const override; - - MIRType *CopyMIRTypeNode() const override - { - return new MIRInterfaceType(*this); - } - - const std::vector &GetInfo() const override - { - return info; - } - void PushbackMIRInfo(const MIRInfoPair &pair) override - { - info.push_back(pair); - } - uint32 GetInfo(const std::string &infoStr) const; - uint32 GetInfo(GStrIdx strIdx) const; - size_t GetInfoSize() const - { - return info.size(); - } - - const MIRInfoPair &GetInfoElemt(size_t n) const override - { - DEBUG_ASSERT(n < info.size(), "array index out of range"); - return info.at(n); - } - - const std::vector &GetInfoIsString() const override - { - return infoIsString; - } - void PushbackIsString(bool isString) override - { - infoIsString.push_back(isString); - } - size_t GetInfoIsStringSize() const - { - return infoIsString.size(); - } - bool GetInfoIsStringElemt(size_t n) const override - { - DEBUG_ASSERT(n < infoIsString.size(), "array index out of range"); - return infoIsString.at(n); - } - - const MIREncodedArray &GetStaticValue() const override - { - return staticValue; - } - void PushbackStaticValue(EncodedValue &encodedValue) override - { - staticValue.push_back(encodedValue); - } - - std::vector &GetParentsTyIdx() - { - return parentsTyIdx; - } - void SetParentsTyIdx(const std::vector &parents) - { - parentsTyIdx = parents; - } - const std::vector &GetParentsTyIdx() const - { - return parentsTyIdx; - } - - TyIdx GetParentsElementTyIdx(size_t i) const - { - DEBUG_ASSERT(i < parentsTyIdx.size(), "array index out of range"); - return parentsTyIdx[i]; - } - - void SetParentsElementTyIdx(size_t i, TyIdx tyIdx) - { - DEBUG_ASSERT(i < parentsTyIdx.size(), "array index out of range"); - parentsTyIdx[i] = tyIdx; - } -#ifdef ARK_LITECG_DEBUG - void Dump(int indent, bool dontUseName = false) const override; -#endif - bool HasVolatileField() const override; - bool HasTypeParam() const override; - FieldPair TraverseToFieldRef(FieldID &fieldID) const override; - void SetComplete() override - { - typeKind = kTypeInterface; - } - - size_t GetSize() const override; - - void ClearContents() override - { - MIRStructType::ClearContents(); - parentsTyIdx.clear(); - info.clear(); - infoIsString.clear(); - staticValue.clear(); - } - - size_t GetHashIndex() const override - { - return ((static_cast(nameStrIdx) << kShiftNumOfNameStrIdx) + (typeKind << kShiftNumOfTypeKind)) % - kTypeHashLength; - } - - bool HasFields() const override - { - return false; - } - uint32 NumberOfFieldIDs() const override - { - return 0; - } - MIRStructType *EmbeddedStructType() override - { - return nullptr; - } - -private: - std::vector parentsTyIdx {}; // multiple inheritence - std::vector info {}; - std::vector infoIsString {}; - MIREncodedArray staticValue {}; // DELETE THIS -}; - class MIRBitFieldType : public MIRType { public: MIRBitFieldType(uint8 field, PrimType pt) : MIRType(kTypeBitField, pt), fieldSize(field) {} @@ -2513,7 +1674,6 @@ MIRType *GetElemType(const MIRType &arrayType); // aarch64 specific bool IsHomogeneousAggregates(const MIRType &ty, PrimType &primType, size_t &elemNum, bool firstDepth = true); bool IsParamStructCopyToMemory(const MIRType &ty); -bool IsReturnInMemory(const MIRType &ty); #endif // MIR_FEATURE_FULL } // namespace maple diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/global_tables.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/global_tables.cpp index 2b67e7569b..55e3d369eb 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/global_tables.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/global_tables.cpp @@ -270,60 +270,12 @@ MIRType *TypeTable::GetOrCreateFunctionType(const TyIdx &retTyIdx, const std::ve return typeTable.at(tyIdx); } -MIRType *TypeTable::GetOrCreateStructOrUnion(const std::string &name, const FieldVector &fields, - const FieldVector &parentFields, MIRModule &module, bool forStruct, - const TypeAttrs &attrs) -{ - GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); - MIRStructType type(forStruct ? kTypeStruct : kTypeUnion, strIdx); - type.SetFields(fields); - type.SetParentFields(parentFields); - type.SetTypeAttrs(attrs); - - TyIdx tyIdx = GetOrCreateMIRType(&type); - // Global? - module.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); - module.PushbackTypeDefOrder(strIdx); - DEBUG_ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateStructOrUnion"); - return typeTable.at(tyIdx); -} - void TypeTable::PushIntoFieldVector(FieldVector &fields, const std::string &name, const MIRType &type) { GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); fields.push_back(FieldPair(strIdx, TyIdxFieldAttrPair(type.GetTypeIndex(), FieldAttrs()))); } -MIRType *TypeTable::GetOrCreateClassOrInterface(const std::string &name, MIRModule &module, bool forClass) -{ - GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(name); - TyIdx tyIdx = module.GetTypeNameTab()->GetTyIdxFromGStrIdx(strIdx); - if (!tyIdx) { - if (forClass) { - MIRClassType type(kTypeClassIncomplete, strIdx); // for class type - tyIdx = GetOrCreateMIRType(&type); - } else { - MIRInterfaceType type(kTypeInterfaceIncomplete, strIdx); // for interface type - tyIdx = GetOrCreateMIRType(&type); - } - module.PushbackTypeDefOrder(strIdx); - module.GetTypeNameTab()->SetGStrIdxToTyIdx(strIdx, tyIdx); - if (typeTable[tyIdx]->GetNameStrIdx() == 0u) { - typeTable[tyIdx]->SetNameStrIdx(strIdx); - } - } - DEBUG_ASSERT(tyIdx < typeTable.size(), "index out of range in TypeTable::GetOrCreateClassOrInterface"); - return typeTable.at(tyIdx); -} - -void TypeTable::AddFieldToStructType(MIRStructType &structType, const std::string &fieldName, const MIRType &fieldType) -{ - GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(fieldName); - FieldAttrs fieldAttrs; - fieldAttrs.SetAttr(FLDATTR_final); // Mark compiler-generated struct fields as final to improve AliasAnalysis - structType.GetFields().push_back(FieldPair(strIdx, TyIdxFieldAttrPair(fieldType.GetTypeIndex(), fieldAttrs))); -} - void FPConstTable::PostInit() { MIRType &typeFloat = *GlobalTables::GetTypeTable().GetPrimType(PTY_f32); diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/intrinsics.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/intrinsics.cpp index 85e19186fb..5bcfd3771d 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/intrinsics.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/intrinsics.cpp @@ -27,52 +27,6 @@ IntrinDesc IntrinDesc::intrinTable[INTRN_LAST + 1] = { #include "intrinsics.def" #undef DEF_MIR_INTRINSIC }; -MIRType *IntrinDesc::GetOrCreateJSValueType() -{ - if (jsValueType != nullptr) { - return jsValueType; - } - MIRBuilder *jsBuilder = mirModule->GetMIRBuilder(); - FieldVector payloadFields; - GStrIdx i32 = jsBuilder->GetOrCreateStringIndex("i32"); - GStrIdx u32 = jsBuilder->GetOrCreateStringIndex("u32"); - GStrIdx boo = jsBuilder->GetOrCreateStringIndex("boo"); - GStrIdx ptr = jsBuilder->GetOrCreateStringIndex("ptr"); - payloadFields.push_back( - FieldPair(i32, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetInt32()->GetTypeIndex(), FieldAttrs()))); - payloadFields.push_back( - FieldPair(u32, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetUInt32()->GetTypeIndex(), FieldAttrs()))); - payloadFields.push_back( - FieldPair(boo, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetUInt32()->GetTypeIndex(), FieldAttrs()))); - payloadFields.push_back( - FieldPair(ptr, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetVoidPtr()->GetTypeIndex(), FieldAttrs()))); - FieldVector parentFields; - MIRType *payloadType = - GlobalTables::GetTypeTable().GetOrCreateUnionType("payload_type", payloadFields, parentFields, *mirModule); - FieldVector sFields; - GStrIdx payload = jsBuilder->GetOrCreateStringIndex("payload"); - GStrIdx tag = jsBuilder->GetOrCreateStringIndex("tag"); - sFields.push_back(FieldPair(payload, TyIdxFieldAttrPair(payloadType->GetTypeIndex(), FieldAttrs()))); - sFields.push_back( - FieldPair(tag, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetUInt32()->GetTypeIndex(), FieldAttrs()))); - MIRType *sType = GlobalTables::GetTypeTable().GetOrCreateStructType("s_type", sFields, parentFields, *mirModule); - CHECK_FATAL(sType != nullptr, "can't get struct type, check it!"); - FieldVector jsValLayoutFields; - GStrIdx asBits = jsBuilder->GetOrCreateStringIndex("asBits"); - GStrIdx s = jsBuilder->GetOrCreateStringIndex("s"); - GStrIdx asDouble = jsBuilder->GetOrCreateStringIndex("asDouble"); - GStrIdx asPtr = jsBuilder->GetOrCreateStringIndex("asPtr"); - jsValLayoutFields.push_back( - FieldPair(asBits, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetUInt64()->GetTypeIndex(), FieldAttrs()))); - jsValLayoutFields.push_back(FieldPair(s, TyIdxFieldAttrPair(sType->GetTypeIndex(), FieldAttrs()))); - jsValLayoutFields.push_back(FieldPair( - asDouble, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetDouble()->GetTypeIndex(), FieldAttrs()))); - jsValLayoutFields.push_back( - FieldPair(asPtr, TyIdxFieldAttrPair(GlobalTables::GetTypeTable().GetVoidPtr()->GetTypeIndex(), FieldAttrs()))); - MIRType *jsValLayoutType = GlobalTables::GetTypeTable().GetOrCreateUnionType("jsval_layout_type", jsValLayoutFields, - parentFields, *mirModule); - return jsValLayoutType; -} void IntrinDesc::InitMIRModule(MIRModule *mod) { diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_builder.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_builder.cpp index 6b34244145..823e842e44 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_builder.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_builder.cpp @@ -17,212 +17,6 @@ #include "mir_symbol_builder.h" namespace maple { -// This is for compiler-generated metadata 1-level struct -void MIRBuilder::AddIntFieldConst(const MIRStructType &sType, MIRAggConst &newConst, uint32 fieldID, int64 constValue) -{ - DEBUG_ASSERT(fieldID > 0, "must not be zero"); - auto *fieldConst = - GlobalTables::GetIntConstTable().GetOrCreateIntConst(constValue, *sType.GetElemType(fieldID - 1)); - newConst.AddItem(fieldConst, fieldID); -} - -// This is for compiler-generated metadata 1-level struct -void MIRBuilder::AddAddrofFieldConst(const MIRStructType &structType, MIRAggConst &newConst, uint32 fieldID, - const MIRSymbol &fieldSymbol) -{ - AddrofNode *fieldExpr = CreateExprAddrof(0, fieldSymbol, mirModule->GetMemPool()); - DEBUG_ASSERT(fieldID > 0, "must not be zero"); - auto *fieldConst = mirModule->GetMemPool()->New(fieldExpr->GetStIdx(), fieldExpr->GetFieldID(), - *structType.GetElemType(fieldID - 1)); - newConst.AddItem(fieldConst, fieldID); -} - -// This is for compiler-generated metadata 1-level struct -void MIRBuilder::AddAddroffuncFieldConst(const MIRStructType &structType, MIRAggConst &newConst, uint32 fieldID, - const MIRSymbol &funcSymbol) -{ - MIRConst *fieldConst = nullptr; - MIRFunction *vMethod = funcSymbol.GetFunction(); - if (vMethod->IsAbstract()) { - DEBUG_ASSERT(fieldID > 0, "must not be zero"); - fieldConst = GlobalTables::GetIntConstTable().GetOrCreateIntConst(0, *structType.GetElemType(fieldID - 1)); - } else { - AddroffuncNode *addrofFuncExpr = - CreateExprAddroffunc(funcSymbol.GetFunction()->GetPuidx(), mirModule->GetMemPool()); - DEBUG_ASSERT(fieldID > 0, "must not be zero"); - fieldConst = mirModule->GetMemPool()->New(addrofFuncExpr->GetPUIdx(), - *structType.GetElemType(fieldID - 1)); - } - newConst.AddItem(fieldConst, fieldID); -} - -// fieldID is continuously being updated during traversal; -// when the field is found, its field id is returned via fieldID -bool MIRBuilder::TraverseToNamedField(MIRStructType &structType, GStrIdx nameIdx, uint32 &fieldID) -{ - TyIdx tid(0); - return TraverseToNamedFieldWithTypeAndMatchStyle(structType, nameIdx, tid, fieldID, kMatchAnyField); -} - -// traverse parent first but match self first. -void MIRBuilder::TraverseToNamedFieldWithType(MIRStructType &structType, GStrIdx nameIdx, TyIdx typeIdx, - uint32 &fieldID, uint32 &idx) -{ - if (structType.IsIncomplete()) { - (void)incompleteTypeRefedSet.insert(structType.GetTypeIndex()); - } - // process parent - if (structType.GetKind() == kTypeClass || structType.GetKind() == kTypeClassIncomplete) { - auto &classType = static_cast(structType); - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(classType.GetParentTyIdx()); - auto *parentType = static_cast(type); - if (parentType != nullptr) { - ++fieldID; - TraverseToNamedFieldWithType(*parentType, nameIdx, typeIdx, fieldID, idx); - } - } - for (uint32 fieldIdx = 0; fieldIdx < structType.GetFieldsSize(); ++fieldIdx) { - ++fieldID; - TyIdx fieldTyIdx = structType.GetFieldsElemt(fieldIdx).second.first; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - if (structType.GetFieldsElemt(fieldIdx).first == nameIdx) { - if (typeIdx == 0u || fieldTyIdx == typeIdx) { - idx = fieldID; - continue; - } - // for pointer type, check their pointed type - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(typeIdx); - if (type->IsOfSameType(*fieldType)) { - idx = fieldID; - } - } - - if (fieldType->IsStructType()) { - auto *subStructType = static_cast(fieldType); - TraverseToNamedFieldWithType(*subStructType, nameIdx, typeIdx, fieldID, idx); - } - } -} - -// fieldID is continuously being updated during traversal; -// when the field is found, its field id is returned via fieldID -// -// typeidx: TyIdx(0) means do not check types. -// matchstyle: 0: do not match but traverse to update fieldID -// 1: match top level field only -// 2: match any field -// 4: traverse parent first -// 0xc: do not match but traverse to update fieldID, traverse parent first, found in child -bool MIRBuilder::TraverseToNamedFieldWithTypeAndMatchStyle(MIRStructType &structType, GStrIdx nameIdx, TyIdx typeIdx, - uint32 &fieldID, unsigned int matchStyle) -{ - if (structType.IsIncomplete()) { - (void)incompleteTypeRefedSet.insert(structType.GetTypeIndex()); - } - if (matchStyle & kParentFirst) { - // process parent - if ((structType.GetKind() != kTypeClass) && (structType.GetKind() != kTypeClassIncomplete)) { - return false; - } - - auto &classType = static_cast(structType); - MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(classType.GetParentTyIdx()); - auto *parentType = static_cast(type); - if (parentType != nullptr) { - ++fieldID; - if (matchStyle == (kFoundInChild | kParentFirst | kUpdateFieldID)) { - matchStyle = kParentFirst; - uint32 idxBackup = nameIdx; - nameIdx.reset(); - // do not match but traverse to update fieldID, traverse parent first - TraverseToNamedFieldWithTypeAndMatchStyle(*parentType, nameIdx, typeIdx, fieldID, matchStyle); - nameIdx.reset(idxBackup); - } else if (TraverseToNamedFieldWithTypeAndMatchStyle(*parentType, nameIdx, typeIdx, fieldID, matchStyle)) { - return true; - } - } - } - for (uint32 fieldIdx = 0; fieldIdx < structType.GetFieldsSize(); ++fieldIdx) { - ++fieldID; - TyIdx fieldTyIdx = structType.GetFieldsElemt(fieldIdx).second.first; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - DEBUG_ASSERT(fieldType != nullptr, "fieldType is null"); - if (matchStyle && structType.GetFieldsElemt(fieldIdx).first == nameIdx) { - if (typeIdx == 0u || fieldTyIdx == typeIdx || - fieldType->IsOfSameType(*GlobalTables::GetTypeTable().GetTypeFromTyIdx(typeIdx))) { - return true; - } - } - unsigned int style = matchStyle & kMatchAnyField; - if (fieldType->IsStructType()) { - auto *subStructType = static_cast(fieldType); - if (TraverseToNamedFieldWithTypeAndMatchStyle(*subStructType, nameIdx, typeIdx, fieldID, style)) { - return true; - } - } - } - return false; -} - -FieldID MIRBuilder::GetStructFieldIDFromNameAndType(MIRType &type, const std::string &name, TyIdx idx, - unsigned int matchStyle) -{ - auto &structType = static_cast(type); - uint32 fieldID = 0; - GStrIdx strIdx = GetStringIndex(name); - if (TraverseToNamedFieldWithTypeAndMatchStyle(structType, strIdx, idx, fieldID, matchStyle)) { - return fieldID; - } - return 0; -} - -FieldID MIRBuilder::GetStructFieldIDFromNameAndType(MIRType &type, const std::string &name, TyIdx idx) -{ - return GetStructFieldIDFromNameAndType(type, name, idx, kMatchAnyField); -} - -FieldID MIRBuilder::GetStructFieldIDFromNameAndTypeParentFirst(MIRType &type, const std::string &name, TyIdx idx) -{ - return GetStructFieldIDFromNameAndType(type, name, idx, kParentFirst); -} - -FieldID MIRBuilder::GetStructFieldIDFromNameAndTypeParentFirstFoundInChild(MIRType &type, const std::string &name, - TyIdx idx) -{ - // do not match but traverse to update fieldID, traverse parent first, found in child - return GetStructFieldIDFromNameAndType(type, name, idx, kFoundInChild | kParentFirst | kUpdateFieldID); -} - -FieldID MIRBuilder::GetStructFieldIDFromFieldName(MIRType &type, const std::string &name) -{ - return GetStructFieldIDFromNameAndType(type, name, TyIdx(0), kMatchAnyField); -} - -FieldID MIRBuilder::GetStructFieldIDFromFieldNameParentFirst(MIRType *type, const std::string &name) -{ - if (type == nullptr) { - return 0; - } - return GetStructFieldIDFromNameAndType(*type, name, TyIdx(0), kParentFirst); -} - -void MIRBuilder::SetStructFieldIDFromFieldName(MIRStructType &structType, const std::string &name, GStrIdx newStrIdx, - const MIRType &newFieldType) -{ - uint32 fieldID = 0; - GStrIdx strIdx = GetStringIndex(name); - while (true) { - if (structType.GetElemStrIdx(fieldID) == strIdx) { - if (newStrIdx != 0u) { - structType.SetElemStrIdx(fieldID, newStrIdx); - } - structType.SetElemtTyIdx(fieldID, newFieldType.GetTypeIndex()); - return; - } - ++fieldID; - } -} - // create a function named str MIRFunction *MIRBuilder::GetOrCreateFunction(const std::string &str, TyIdx retTyIdx) { diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp index b2aa7f9b6a..e620f4ac2b 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_function.cpp @@ -24,7 +24,6 @@ namespace { using namespace maple; enum FuncProp : uint32_t { kFuncPropHasCall = 1U, // the function has call - kFuncPropRetStruct = 1U << 1, // the function returns struct kFuncPropUserFunc = 1U << 2, // the function is a user func kFuncPropInfoPrinted = 1U << 3, // to avoid printing frameSize/moduleid/funcSize info more // than once per function since they @@ -32,7 +31,6 @@ enum FuncProp : uint32_t { kFuncPropNeverReturn = 1U << 4, // the function when called never returns kFuncPropHasSetjmp = 1U << 5, // the function contains call to setjmp kFuncPropHasAsm = 1U << 6, // the function has use of inline asm - kFuncPropStructReturnedInRegs = 1U << 7, // the function returns struct in registers }; } // namespace @@ -168,36 +166,6 @@ void MIRFunction::SetHasCall() flag |= kFuncPropHasCall; } -bool MIRFunction::IsReturnStruct() const -{ - return flag & kFuncPropRetStruct; -} -void MIRFunction::SetReturnStruct() -{ - flag |= kFuncPropRetStruct; -} -void MIRFunction::SetReturnStruct(const MIRType &retType) -{ - if (retType.IsStructType()) { - flag |= kFuncPropRetStruct; - } -} -void MIRFunction::SetReturnStruct(const MIRType *retType) -{ - switch (retType->GetKind()) { - case kTypeUnion: - case kTypeStruct: - case kTypeStructIncomplete: - case kTypeClass: - case kTypeClassIncomplete: - case kTypeInterface: - case kTypeInterfaceIncomplete: - flag |= kFuncPropRetStruct; - break; - default:; - } -} - bool MIRFunction::IsUserFunc() const { return flag & kFuncPropUserFunc; @@ -249,16 +217,6 @@ bool MIRFunction::HasAsm() const return ((flag & kFuncPropHasAsm) != kTypeflagZero); } -void MIRFunction::SetStructReturnedInRegs() -{ - flag |= kFuncPropStructReturnedInRegs; -} - -bool MIRFunction::StructReturnedInRegs() const -{ - return ((flag & kFuncPropStructReturnedInRegs) != kTypeflagZero); -} - void MIRFunction::SetAttrsFromSe(uint8 specialEffect) { // NoPrivateDefEffect diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_lower.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_lower.cpp index 4b519f6ded..9ae827d754 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_lower.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_lower.cpp @@ -789,11 +789,6 @@ MIRFuncType *MIRLower::FuncTypeFromFuncPtrExpr(BaseNode *x) if (preg->GetOp() == OP_dread) { const MIRSymbol *symbol = preg->rematInfo.sym; MIRType *mirType = symbol->GetType(); - if (preg->fieldID != 0) { - MIRStructType *structty = static_cast(mirType); - FieldPair thepair = structty->TraverseToField(preg->fieldID); - mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); - } if (mirType->GetKind() == kTypePointer) { res = static_cast(mirType)->GetPointedFuncType(); @@ -821,11 +816,6 @@ MIRFuncType *MIRLower::FuncTypeFromFuncPtrExpr(BaseNode *x) DreadNode *dread = static_cast(x); MIRSymbol *symbol = func->GetLocalOrGlobalSymbol(dread->GetStIdx()); MIRType *mirType = symbol->GetType(); - if (dread->GetFieldID() != 0) { - MIRStructType *structty = static_cast(mirType); - FieldPair thepair = structty->TraverseToField(dread->GetFieldID()); - mirType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(thepair.second.first); - } if (mirType->GetKind() == kTypePointer) { res = static_cast(mirType)->GetPointedFuncType(); } diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_module.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_module.cpp index 0613509fb2..a122e42bfd 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_module.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_module.cpp @@ -246,18 +246,6 @@ void MIRModule::DumpGlobals(bool emitStructureType) const const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(*it); MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); DEBUG_ASSERT(type != nullptr, "type should not be nullptr here"); - bool isStructType = type->IsStructType(); - if (isStructType) { - auto *structType = static_cast(type); - // still emit what in extern_structtype_set_ - if (!emitStructureType && - externStructTypeSet.find(structType->GetTypeIndex()) == externStructTypeSet.end()) { - continue; - } - if (structType->IsImported()) { - continue; - } - } LogInfo::MapleLogger() << "type $" << name << " "; if (type->GetKind() == kTypeByName) { @@ -395,13 +383,6 @@ void MIRModule::DumpDefType() const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(*it); MIRType *type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); DEBUG_ASSERT(type != nullptr, "type should not be nullptr here"); - bool isStructType = type->IsStructType(); - if (isStructType) { - auto *structType = static_cast(type); - if (structType->IsImported()) { - continue; - } - } LogInfo::MapleLogger() << "type $" << name << " "; if (type->GetKind() == kTypeByName) { LogInfo::MapleLogger() << "void"; @@ -480,85 +461,6 @@ const std::string &MIRModule::GetFileNameFromFileNum(uint32 fileNum) const } #ifdef ARK_LITECG_DEBUG -void MIRModule::DumpTypeTreeToCxxHeaderFile(MIRType &ty, std::unordered_set &dumpedClasses) const -{ - if (dumpedClasses.find(&ty) != dumpedClasses.end()) { - return; - } - // first, insert ty to the dumped_classes to prevent infinite recursion - (void)dumpedClasses.insert(&ty); - DEBUG_ASSERT(ty.GetKind() == kTypeClass || ty.GetKind() == kTypeStruct || ty.GetKind() == kTypeUnion || - ty.GetKind() == kTypeInterface, - "Unexpected MIRType."); - /* No need to emit interfaces; because "interface variables are - final and static by default and methods are public and abstract" - */ - if (ty.GetKind() == kTypeInterface) { - return; - } - // dump all of its parents - if (srcLang == kSrcLangC || srcLang == kSrcLangCPlusPlus) { - DEBUG_ASSERT((ty.GetKind() == kTypeStruct || ty.GetKind() == kTypeUnion), - "type should be either struct or union"); - } else { - DEBUG_ASSERT(false, "source languages other than C/C++ are not supported yet"); - } - if (srcLang == kSrcLangC || srcLang == kSrcLangCPlusPlus) { - // how to access parent fields???? - DEBUG_ASSERT(false, "not yet implemented"); - } -} - -void MIRModule::DumpToCxxHeaderFile(std::set &leafClasses, const std::string &pathToOutf) const -{ - if (pathToOutf.empty()) { - return; - } - std::ofstream mpltFile; - mpltFile.open(pathToOutf, std::ios::trunc); - std::streambuf *backup = LogInfo::MapleLogger().rdbuf(); - LogInfo::MapleLogger().rdbuf(mpltFile.rdbuf()); // change cout's buffer to that of file - char *headerGuard = strdup(pathToOutf.c_str()); - CHECK_FATAL(headerGuard != nullptr, "strdup failed"); - for (char *p = headerGuard; *p; ++p) { - if (!isalnum(*p)) { - *p = '_'; - } else if (isalpha(*p) && islower(*p)) { - *p = toupper(*p); - } - } - // define a hash table - std::unordered_set dumpedClasses; - const char *prefix = "__SRCLANG_UNKNOWN_"; - if (srcLang == kSrcLangC || srcLang == kSrcLangCPlusPlus) { - prefix = "__SRCLANG_CXX_"; - } - LogInfo::MapleLogger() << "#ifndef " << prefix << headerGuard << "__\n"; - LogInfo::MapleLogger() << "#define " << prefix << headerGuard << "__\n"; - LogInfo::MapleLogger() << "/* this file is compiler-generated; do not edit */\n\n"; - LogInfo::MapleLogger() << "#include \n"; - LogInfo::MapleLogger() << "#include \n"; - for (auto &s : leafClasses) { - CHECK_FATAL(!s.empty(), "string is null"); - GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(s); - TyIdx tyIdx = typeNameTab->GetTyIdxFromGStrIdx(strIdx); - MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx); - if (ty == nullptr) { - continue; - } - DEBUG_ASSERT(ty->GetKind() == kTypeClass || ty->GetKind() == kTypeStruct || ty->GetKind() == kTypeUnion || - ty->GetKind() == kTypeInterface, - ""); - DumpTypeTreeToCxxHeaderFile(*ty, dumpedClasses); - } - LogInfo::MapleLogger() << "#endif /* " << prefix << headerGuard << "__ */\n"; - /* restore cout */ - LogInfo::MapleLogger().rdbuf(backup); - free(headerGuard); - headerGuard = nullptr; - mpltFile.close(); -} - void MIRModule::DumpClassToFile(const std::string &path) const { std::string strPath(path); diff --git a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_nodes.cpp b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_nodes.cpp index e57b7e4010..63cf729331 100755 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_nodes.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_nodes.cpp @@ -68,76 +68,11 @@ bool BaseNode::MayThrowException() return false; } -bool AddrofNode::CheckNode(const MIRModule &mod) const -{ - const MIRSymbol *st = mod.CurFunction()->GetLocalOrGlobalSymbol(GetStIdx()); - DEBUG_ASSERT(st != nullptr, "null ptr check"); - MIRType *ty = st->GetType(); - switch (ty->GetKind()) { - case kTypeScalar: { - return IsPrimitiveScalar(GetPrimType()); - } - case kTypeArray: { - return GetPrimType() == PTY_agg; - } - case kTypeUnion: - case kTypeStruct: - case kTypeStructIncomplete: { - if (GetFieldID() == 0) { - return GetPrimType() == PTY_agg; - } - auto *structType = static_cast(ty); - TyIdx fTyIdx = structType->GetFieldTyIdx(fieldID); - MIRType *subType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fTyIdx); - MIRTypeKind subKind = subType->GetKind(); - return (subKind == kTypeBitField) || - (subKind == kTypeScalar && IsPrimitiveScalar(GetPrimType())) || - (subKind == kTypePointer && IsPrimitivePoint(GetPrimType())) || - (subKind == kTypeStruct && GetPrimType() == PTY_agg) || (fTyIdx != 0u && GetPrimType() == PTY_agg); - } - case kTypeClass: - case kTypeClassIncomplete: { - if (fieldID == 0) { - return GetPrimType() == PTY_agg; - } - auto *classType = static_cast(ty); - MIRType *subType = classType->GetFieldType(fieldID); - MIRTypeKind subKind = subType->GetKind(); - return (subKind == kTypeBitField) || - (subKind == kTypeScalar && IsPrimitiveScalar(GetPrimType())) || - (subKind == kTypePointer && IsPrimitivePoint(GetPrimType())) || - (subKind == kTypeStruct && GetPrimType() == PTY_agg); - } - case kTypeInterface: - case kTypeInterfaceIncomplete: { - if (fieldID == 0) { - return GetPrimType() == PTY_agg; - } - auto *interfaceType = static_cast(ty); - MIRType *subType = interfaceType->GetFieldType(fieldID); - MIRTypeKind subKind = subType->GetKind(); - return (subKind == kTypeBitField) || - (subKind == kTypeScalar && IsPrimitiveScalar(GetPrimType())) || - (subKind == kTypePointer && IsPrimitivePoint(GetPrimType())) || - (subKind == kTypeStruct && GetPrimType() == PTY_agg); - } - case kTypePointer: - return IsPrimitivePoint(GetPrimType()); - case kTypeParam: - case kTypeGenericInstant: - return true; - default: - return false; - } -} - MIRType *IreadNode::GetType() const { MIRPtrType *ptrtype = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(tyIdx)); - if (fieldID == 0) { - return ptrtype->GetPointedType(); - } - return GlobalTables::GetTypeTable().GetTypeFromTyIdx(ptrtype->GetPointedTyIdxWithFieldID(fieldID)); + CHECK_FATAL(fieldID == 0, "fieldID must be 0"); + return ptrtype->GetPointedType(); } bool IreadNode::IsVolatile() const @@ -1435,26 +1370,6 @@ inline MIRTypeKind GetPointedTypeKind(TyIdx tyIdx) return pointedType->GetKind(); } -MIRTypeKind GetFieldTypeKind(MIRStructType *structType, FieldID fieldId) -{ - TyIdx fieldTyIdx; - if (fieldId > 0) { - MIRType *mirType = structType->GetFieldType(fieldId); - fieldTyIdx = mirType->GetTypeIndex(); - } else { - DEBUG_ASSERT(static_cast(-fieldId) < structType->GetParentFieldsSize() + 1, - "array index out of range"); - fieldTyIdx = structType->GetParentFieldsElemt(-fieldId - 1).second.first; - } - return GetTypeKind(fieldTyIdx); -} - -inline bool IsStructureTypeKind(MIRTypeKind kind) -{ - return kind == kTypeStruct || kind == kTypeStructIncomplete || kind == kTypeUnion || kind == kTypeClass || - kind == kTypeClassIncomplete || kind == kTypeInterface || kind == kTypeInterfaceIncomplete; -} - bool IsSignedType(const BaseNode *opnd) { switch (opnd->GetPrimType()) { 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 970efa13f0..792abd4c89 100644 --- a/ecmascript/compiler/codegen/maple/maple_ir/src/mir_type.cpp +++ b/ecmascript/compiler/codegen/maple/maple_ir/src/mir_type.cpp @@ -520,20 +520,6 @@ static inline uint64 RoundUp(uint64 offset, uint32 align) return RoundUpConst(offset, align); } -static constexpr uint64 RoundDownConst(uint64 offset, uint32 align) -{ - uint64 temp = static_cast(-align); - return temp & offset; -} - -static inline uint64 RoundDown(uint64 offset, uint32 align) -{ - if (align == 0) { - return offset; - } - return RoundDownConst(offset, align); -} - size_t MIRArrayType::GetSize() const { if (size != kInvalidSize) { @@ -607,41 +593,13 @@ std::string MIRFarrayType::GetCompactMplTypeName() const return ss.str(); } -MIRStructType *MIRJarrayType::GetParentType() -{ - return static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); -} - void MIRJarrayType::DetermineName() { if (jNameStrIdx != 0u) { return; // already determined } - MIRType *elemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(GetElemTyIdx()); dim = 1; std::string baseName; - while (true) { - if (elemType->GetKind() == kTypePointer) { - auto *pType = static_cast(elemType)->GetPointedType(); - DEBUG_ASSERT(pType != nullptr, "pType is null in MIRJarrayType::DetermineName"); - if (pType->GetKind() == kTypeByName || pType->GetKind() == kTypeClass || - pType->GetKind() == kTypeInterface || pType->GetKind() == kTypeClassIncomplete || - pType->GetKind() == kTypeInterfaceIncomplete) { - baseName = static_cast(pType)->GetName(); - fromPrimitive = false; - break; - } else if (pType->GetKind() == kTypeJArray) { - auto *tmpPtype = static_cast(pType); - elemType = tmpPtype->GetElemType(); - DEBUG_ASSERT(elemType != nullptr, "elemType is null in MIRJarrayType::DetermineName"); - ++dim; - } else { - DEBUG_ASSERT(false, "unexpected type!"); - } - } else { - DEBUG_ASSERT(false, "unexpected type!"); - } - } std::string name; for (int i = dim; i > 0; --i) { name += JARRAY_PREFIX_STR; @@ -657,10 +615,8 @@ MIRType *MIRPtrType::GetPointedType() const bool MIRType::IsVolatile(int fieldID) const { - if (fieldID == 0) { - return HasVolatileField(); - } - return static_cast(this)->IsFieldVolatile(fieldID); + CHECK_FATAL(fieldID == 0, "fieldID must be 0"); + return HasVolatileField(); } bool MIRPtrType::HasTypeParam() const @@ -696,553 +652,7 @@ void MIRBitFieldType::Dump(int indent, bool dontUseName) const } #endif -size_t MIRClassType::GetSize() const -{ - if (parentTyIdx == 0u) { - return MIRStructType::GetSize(); - } - if (size != kInvalidSize) { - return size; - } - const auto *parentType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); - size_t parentSize = parentType->GetSize(); - if (parentSize == 0) { - return 0; - } - size_t structSize = MIRStructType::GetSize(); - if (structSize == 0) { - return 0; - } - size = parentSize + structSize; - return size; -} - -FieldID MIRClassType::GetFirstLocalFieldID() const -{ - if (!IsLocal()) { - return 0; - } - if (parentTyIdx == 0u) { - return 1; - } - - constexpr uint8 lastFieldIDOffset = 2; - constexpr uint8 firstLocalFieldIDOffset = 1; - const auto *parentClassType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); - return !parentClassType->IsLocal() ? parentClassType->GetLastFieldID() + lastFieldIDOffset - : parentClassType->GetFirstLocalFieldID() + firstLocalFieldIDOffset; -} - -FieldID MIRClassType::GetLastFieldID() const -{ - FieldID fieldID = static_cast(fields.size()); - if (parentTyIdx != 0u) { - const auto *parentClassType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); - if (parentClassType != nullptr) { - fieldID += parentClassType->GetLastFieldID() + 1; - } - } - return fieldID; -} - #ifdef ARK_LITECG_DEBUG -static void DumpClassOrInterfaceInfo(const MIRStructType &type, int indent) -{ - const std::vector &info = type.GetInfo(); - std::vector infoIsString = type.GetInfoIsString(); - size_t size = info.size(); - for (size_t i = 0; i < size; ++i) { - LogInfo::MapleLogger() << '\n'; - PrintIndentation(indent); - LogInfo::MapleLogger() << "@" << GlobalTables::GetStrTable().GetStringFromStrIdx(info[i].first) << " "; - if (!infoIsString[i]) { - LogInfo::MapleLogger() << info[i].second; - } else { - LogInfo::MapleLogger() << "\"" << GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(info[i].second)) - << "\""; - } - if (i != size - 1) { - LogInfo::MapleLogger() << ","; - } - } -} -#endif - -static uint32 GetInfoFromStrIdx(const std::vector &info, const GStrIdx &strIdx) -{ - for (MIRInfoPair infoPair : info) { - if (infoPair.first == strIdx) { - return infoPair.second; - } - } - return 0; -} - -uint32 MIRInterfaceType::GetInfo(GStrIdx strIdx) const -{ - return GetInfoFromStrIdx(info, strIdx); -} - -// return class id or superclass id accroding to input string -uint32 MIRInterfaceType::GetInfo(const std::string &infoStr) const -{ - GStrIdx strIdx = GlobalTables::GetStrTable().GetStrIdxFromName(infoStr); - return GetInfo(strIdx); -} -size_t MIRInterfaceType::GetSize() const -{ - if (size != kInvalidSize) { - return size; - } - size = MIRStructType::GetSize(); - if (parentsTyIdx.empty()) { - return size; - } - if (size == 0) { - return 0; - } - for (size_t i = 0; i < parentsTyIdx.size(); ++i) { - const auto *parentType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentsTyIdx[i])); - size_t parentSize = parentType->GetSize(); - if (parentSize == 0) { - return 0; - } - size += parentSize; - } - return size; -} - -#ifdef ARK_LITECG_DEBUG -static void DumpFields(FieldVector fields, int indent, bool otherFields = false) -{ - size_t size = fields.size(); - for (size_t i = 0; i < size; ++i) { - LogInfo::MapleLogger() << '\n'; - PrintIndentation(indent); - LogInfo::MapleLogger() << ((!otherFields) ? "@" : "^") - << GlobalTables::GetStrTable().GetStringFromStrIdx(fields[i].first) << " "; - GlobalTables::GetTypeTable().GetTypeFromTyIdx(fields[i].second.first)->Dump(indent + 1); - FieldAttrs &fa = fields[i].second.second; - fa.DumpAttributes(); - if (fa.GetAttr(FLDATTR_static) && fa.GetAttr(FLDATTR_final) && - (fa.GetAttr(FLDATTR_public) || fa.GetAttr(FLDATTR_protected))) { - const char *fieldName = GlobalTables::GetStrTable().GetStringFromStrIdx(fields[i].first).c_str(); - MIRSymbol *fieldVar = GlobalTables::GetGsymTable().GetSymbolFromStrIdx( - GlobalTables::GetStrTable().GetStrIdxFromName(fieldName)); - if (fieldVar != nullptr && fieldVar->GetKonst() != nullptr && - fieldVar->GetKonst()->GetKind() == kConstStr16Const) { - LogInfo::MapleLogger() << " = "; - fieldVar->GetKonst()->Dump(); - } - } - if (i != size - 1) { - LogInfo::MapleLogger() << ","; - } - } -} - -static void DumpFieldsAsCxx(const FieldVector &fields, int indent) -{ - for (auto &f : fields) { - PrintIndentation(indent); - const FieldAttrs &fa = f.second.second; - if (fa.GetAttr(FLDATTR_static)) { - LogInfo::MapleLogger() << "// "; - } - LogInfo::MapleLogger() << "/* "; - fa.DumpAttributes(); - GlobalTables::GetTypeTable().GetTypeFromTyIdx(f.second.first)->Dump(indent + 1); - LogInfo::MapleLogger() << " */ "; - GlobalTables::GetTypeTable().GetTypeFromTyIdx(f.second.first)->DumpAsCxx(indent + 1); - LogInfo::MapleLogger() << " " << GlobalTables::GetStrTable().GetStringFromStrIdx(f.first) << ";" << '\n'; - } -} - -static void DumpMethods(MethodVector methods, int indent) -{ - size_t size = methods.size(); - for (size_t i = 0; i < size; ++i) { - LogInfo::MapleLogger() << '\n'; - PrintIndentation(indent); - MIRSymbol *mFirstSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(methods[i].first.Idx()); - DEBUG_ASSERT(mFirstSymbol != nullptr, "null ptr check"); - LogInfo::MapleLogger() << "&" << mFirstSymbol->GetName(); - methods[i].second.second.DumpAttributes(); - LogInfo::MapleLogger() << " ("; - auto *funcType = - static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(methods[i].second.first)); - size_t parmListSize = funcType->GetParamTypeList().size(); - for (size_t j = 0; j < parmListSize; ++j) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetNthParamType(j))->Dump(indent + 1); - if (j != parmListSize - 1) { - LogInfo::MapleLogger() << ","; - } - } - if (funcType->IsVarargs()) { - LogInfo::MapleLogger() << ", ..."; - } - LogInfo::MapleLogger() << ") "; - GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetRetTyIdx())->Dump(indent + 1); - if (i != size - 1) { - LogInfo::MapleLogger() << ","; - } - } -} - -static void DumpConstructorsAsCxx(MethodVector methods, int indent) -{ - unsigned int i = 0; - for (auto &m : methods) { - FuncAttrs &fa = m.second.second; - if (!fa.GetAttr(FUNCATTR_constructor) || !fa.GetAttr(FUNCATTR_public)) { - continue; - } - auto *funcType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(m.second.first)); - PrintIndentation(indent); - MIRSymbol *mFirstSymbol = GlobalTables::GetGsymTable().GetSymbolFromStidx(m.first.Idx()); - DEBUG_ASSERT(mFirstSymbol != nullptr, "null ptr check"); - LogInfo::MapleLogger() << "/* &" << mFirstSymbol->GetName(); - fa.DumpAttributes(); - LogInfo::MapleLogger() << " ("; - unsigned int j = 0; - size_t paramTypeListSize = funcType->GetParamTypeList().size(); - for (auto &p : funcType->GetParamTypeList()) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(p)->Dump(indent + 1); - CHECK_FATAL(paramTypeListSize > 0, "must not be zero"); - if (j != paramTypeListSize - 1) { - LogInfo::MapleLogger() << ", "; - } - ++j; - } - if (funcType->IsVarargs()) { - LogInfo::MapleLogger() << ", ..."; - } - LogInfo::MapleLogger() << ") "; - GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetRetTyIdx())->Dump(indent + 1); - LogInfo::MapleLogger() << " */" << '\n'; - PrintIndentation(indent); - LogInfo::MapleLogger() << "/* "; - LogInfo::MapleLogger() << namemangler::DecodeName(mFirstSymbol->GetName()); - LogInfo::MapleLogger() << " */" << '\n'; - PrintIndentation(indent); - LogInfo::MapleLogger() << "extern \"C\" "; - // return type - GlobalTables::GetTypeTable().GetTypeFromTyIdx(funcType->GetRetTyIdx())->DumpAsCxx(0); - LogInfo::MapleLogger() << " " << mFirstSymbol->GetName() << "( "; - j = 0; - for (auto &p : funcType->GetParamTypeList()) { - GlobalTables::GetTypeTable().GetTypeFromTyIdx(p)->DumpAsCxx(indent + 1); - DEBUG_ASSERT(paramTypeListSize > 0, "paramTypeListSize should not be zero"); - if (j != paramTypeListSize - 1) { - LogInfo::MapleLogger() << ", "; - } - ++j; - } - if (funcType->IsVarargs()) { - LogInfo::MapleLogger() << ", ..."; - } - LogInfo::MapleLogger() << ")"; - DEBUG_ASSERT(methods.size() > 0, "methods.size() should not be zero"); - if (methods.size() - 1 != i++) { - LogInfo::MapleLogger() << ";" << '\n'; - } - } -} - -static void DumpInterfaces(std::vector interfaces, int indent) -{ - size_t size = interfaces.size(); - for (size_t i = 0; i < size; ++i) { - LogInfo::MapleLogger() << '\n'; - PrintIndentation(indent); - GStrIdx stridx = GlobalTables::GetTypeTable().GetTypeFromTyIdx(interfaces[i])->GetNameStrIdx(); - LogInfo::MapleLogger() << "$" << GlobalTables::GetStrTable().GetStringFromStrIdx(stridx); - if (i != size - 1) { - LogInfo::MapleLogger() << ","; - } - } -} -#endif - -size_t MIRStructType::GetSize() const -{ - if (size != kInvalidSize) { - return size; - } - if (typeKind == kTypeUnion) { - if (fields.size() == 0) { - return isCPlusPlus ? 1 : 0; - } - size = 0; - for (size_t i = 0; i < fields.size(); ++i) { - TyIdxFieldAttrPair tfap = GetTyidxFieldAttrPair(i); - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tfap.first); - size_t fldSize = RoundUp(fieldType->GetSize(), tfap.second.GetAlign()); - if (size < fldSize) { - size = fldSize; - } - } - return size; - } - // since there may be bitfields, perform a layout process for the fields - size_t byteOfst = 0; - size_t bitOfst = 0; - constexpr uint32 shiftNum = 3; - for (size_t i = 0; i < fields.size(); ++i) { - TyIdxFieldAttrPair tfap = GetTyidxFieldAttrPair(i); - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tfap.first); - if (fieldType->GetKind() != kTypeBitField) { - if (byteOfst * k8BitSize < bitOfst) { - byteOfst = (bitOfst >> shiftNum) + 1; - } - byteOfst = RoundUp(byteOfst, std::max(fieldType->GetAlign(), tfap.second.GetAlign())); - byteOfst += fieldType->GetSize(); - bitOfst = byteOfst * k8BitSize; - } else { - MIRBitFieldType *bitfType = static_cast(fieldType); - if (bitfType->GetFieldSize() == 0) { // special case, for aligning purpose - bitOfst = RoundUp(bitOfst, GetPrimTypeBitSize(bitfType->GetPrimType())); - byteOfst = bitOfst >> shiftNum; - } else { - DEBUG_ASSERT(bitfType->GetFieldSize() > 0, "bitfType->GetFieldSize() should not be zero"); - CHECK_FATAL((bitOfst <= UINT32_MAX - bitfType->GetFieldSize()), "must not be zero"); - if (RoundDown(bitOfst + bitfType->GetFieldSize() - 1, GetPrimTypeBitSize(bitfType->GetPrimType())) != - RoundDown(bitOfst, GetPrimTypeBitSize(bitfType->GetPrimType()))) { - bitOfst = RoundUp(bitOfst, GetPrimTypeBitSize(bitfType->GetPrimType())); - byteOfst = bitOfst >> shiftNum; - } - bitOfst += bitfType->GetFieldSize(); - byteOfst = bitOfst >> shiftNum; - } - } - } - if ((byteOfst << k8BitShift) < bitOfst) { - byteOfst = (bitOfst >> shiftNum) + 1; - } - byteOfst = RoundUp(byteOfst, GetAlign()); - if (byteOfst == 0 && isCPlusPlus) { - size = 1; - return 1; // empty struct in C++ has size 1 - } - size = byteOfst; - return size; -} - -uint32 MIRStructType::GetAlign() const -{ - return GetAlignAux(false); -} - -// return original align for typedef struct -uint32 MIRStructType::GetTypedefOriginalAlign() const -{ - return GetAlignAux(true); -} - -uint32 MIRStructType::GetAlignAux(bool toGetOriginal) const -{ - if (fields.size() == 0) { - return std::max(1u, GetTypeAttrs().GetAlign()); - } - uint32 maxAlign = 1; - uint32 maxZeroBitFieldAlign = 1; - auto structPack = GetTypeAttrs().GetPack(); - auto packed = GetTypeAttrs().IsPacked(); - for (size_t i = 0; i < fields.size(); ++i) { - TyIdxFieldAttrPair tfap = GetTyidxFieldAttrPair(i); - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tfap.first); - auto originAlign = - fieldType->GetKind() != kTypeBitField ? fieldType->GetAlign() : GetPrimTypeSize(fieldType->GetPrimType()); - uint32 fieldAlign = - (packed || tfap.second.IsPacked()) ? static_cast(1U) : std::min(originAlign, structPack); - fieldAlign = tfap.second.HasAligned() ? std::max(fieldAlign, tfap.second.GetAlign()) : fieldAlign; - fieldAlign = GetTypeAttrs().HasPack() ? std::min(GetTypeAttrs().GetPack(), fieldAlign) : fieldAlign; - CHECK_FATAL(fieldAlign != 0, "expect fieldAlign not equal 0"); - maxAlign = std::max(maxAlign, fieldAlign); - if (fieldType->IsMIRBitFieldType() && static_cast(fieldType)->GetFieldSize() == 0) { - maxZeroBitFieldAlign = std::max(maxZeroBitFieldAlign, GetPrimTypeSize(fieldType->GetPrimType())); - } - } - uint32 attrAlign = GetTypeAttrs().GetAlign(); - if (GetTypeAttrs().IsTypedef()) { - // when calculating typedef's own size, we need to use its original align - if (toGetOriginal) { - // anonymous struct type def - if (GetTypeAttrs().GetOriginType() == nullptr) { - attrAlign = GetTypeAttrs().GetAlign(); - // unanonymous struct type def - } else { - attrAlign = static_cast(GetTypeAttrs().GetOriginType())->GetTypeAttrs().GetAlign(); - } - // when calculating typedef struct is a field of another struct, we need to use its typealign. - } else { - attrAlign = GetTypeAttrs().GetTypeAlign(); - } - } - if (HasZeroWidthBitField()) { - return std::max(attrAlign, std::max(maxZeroBitFieldAlign, maxAlign)); - } - return std::max(attrAlign, maxAlign); -} - -// Used to determine date alignment in ABI. -// In fact, this alignment of type should be in the context of language/ABI, not MIRType. -// For simplicity, we implement it in MIRType now. -// Need check why "packed" is within the context of ABI. -uint32 MIRStructType::GetUnadjustedAlign() const -{ - if (fields.size() == 0) { - return 1u; - } - uint32 maxAlign = 1; - uint32 maxZeroBitFieldAlign = 1; - auto structPack = GetTypeAttrs().GetPack(); - auto packed = GetTypeAttrs().IsPacked(); - for (size_t i = 0; i < fields.size(); ++i) { - TyIdxFieldAttrPair tfap = GetTyidxFieldAttrPair(i); - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(tfap.first); - auto originAlign = - fieldType->GetKind() != kTypeBitField ? fieldType->GetAlign() : GetPrimTypeSize(fieldType->GetPrimType()); - uint32 fieldAlign = - (packed || tfap.second.IsPacked()) ? static_cast(1U) : std::min(originAlign, structPack); - fieldAlign = tfap.second.HasAligned() ? std::max(fieldAlign, tfap.second.GetAlign()) : fieldAlign; - fieldAlign = GetTypeAttrs().HasPack() ? std::min(GetTypeAttrs().GetPack(), fieldAlign) : fieldAlign; - CHECK_FATAL(fieldAlign != 0, "expect fieldAlign not equal 0"); - maxAlign = std::max(maxAlign, fieldAlign); - if (fieldType->IsMIRBitFieldType() && static_cast(fieldType)->GetFieldSize() == 0) { - maxZeroBitFieldAlign = std::max(maxZeroBitFieldAlign, GetPrimTypeSize(fieldType->GetPrimType())); - } - } - if (HasZeroWidthBitField()) { - return std::max(maxZeroBitFieldAlign, maxAlign); - } - return maxAlign; -} - -#ifdef ARK_LITECG_DEBUG -void MIRStructType::DumpFieldsAndMethods(int indent, bool hasMethod) const -{ - DumpFields(fields, indent); - bool hasField = !fields.empty(); - bool hasStaticField = !staticFields.empty(); - if (hasField && hasStaticField) { - LogInfo::MapleLogger() << ","; - } - DumpFields(staticFields, indent, true); - bool hasFieldOrStaticField = hasField || hasStaticField; - bool hasParentField = !parentFields.empty(); - if (hasFieldOrStaticField && hasParentField) { - LogInfo::MapleLogger() << ","; - } - DumpFields(parentFields, indent, true); - if ((hasFieldOrStaticField || hasParentField) && hasMethod) { - LogInfo::MapleLogger() << ","; - } - DumpMethods(methods, indent); -} - -void MIRStructType::Dump(int indent, bool dontUseName) const -{ - if (!dontUseName && CheckAndDumpTypeName(nameStrIdx, nameIsLocal)) { - return; - } - LogInfo::MapleLogger() << ((typeKind == kTypeStruct) ? ""; -} -#endif - -uint32 MIRClassType::GetInfo(GStrIdx strIdx) const -{ - return GetInfoFromStrIdx(info, strIdx); -} - -// return class id or superclass id accroding to input string -uint32 MIRClassType::GetInfo(const std::string &infoStr) const -{ - GStrIdx strIdx = GlobalTables::GetStrTable().GetStrIdxFromName(infoStr); - return GetInfo(strIdx); -} - -bool MIRClassType::IsFinal() const -{ - if (!IsStructType()) { - return false; - } - uint32 attrStrIdx = GetInfo(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("INFO_attribute_string")); - CHECK(attrStrIdx < GlobalTables::GetStrTable().StringTableSize(), "out of range of vector"); - const std::string &kAttrString = GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(attrStrIdx)); - return kAttrString.find(" final ") != std::string::npos; -} - -bool MIRClassType::IsAbstract() const -{ - uint32 attrStrIdx = GetInfo(GlobalTables::GetStrTable().GetOrCreateStrIdxFromName("INFO_attribute_string")); - CHECK(attrStrIdx < GlobalTables::GetStrTable().StringTableSize(), "out of range of vector"); - const std::string &kAttrString = GlobalTables::GetStrTable().GetStringFromStrIdx(GStrIdx(attrStrIdx)); - return kAttrString.find(" abstract ") != std::string::npos; -} - -bool MIRClassType::IsInner() const -{ - const std::string &name = GetName(); - return name.find("_24") != std::string::npos; -} - -#ifdef ARK_LITECG_DEBUG -void MIRClassType::Dump(int indent, bool dontUseName) const -{ - if (!dontUseName && CheckAndDumpTypeName(nameStrIdx, nameIsLocal)) { - return; - } - LogInfo::MapleLogger() << ((typeKind == kTypeClass) ? "Dump(indent + 1); - LogInfo::MapleLogger() << " "; - } - LogInfo::MapleLogger() << "{"; - DumpClassOrInterfaceInfo(*this, indent); - bool hasMethod = !methods.empty(); - bool hasImplementedInterface = !interfacesImplemented.empty(); - DumpFieldsAndMethods(indent, hasMethod || hasImplementedInterface); - if (hasMethod && hasImplementedInterface) { - LogInfo::MapleLogger() << ","; - } - DumpInterfaces(interfacesImplemented, indent); - LogInfo::MapleLogger() << "}>"; -} - -void MIRClassType::DumpAsCxx(int indent) const -{ - LogInfo::MapleLogger() << "{\n"; - DumpFieldsAsCxx(fields, indent); - LogInfo::MapleLogger() << "};\n"; - DumpConstructorsAsCxx(methods, 0); -} - -void MIRInterfaceType::Dump(int indent, bool dontUseName) const -{ - if (!dontUseName && CheckAndDumpTypeName(nameStrIdx, nameIsLocal)) { - return; - } - LogInfo::MapleLogger() << ((typeKind == kTypeInterface) ? "Dump(0); - LogInfo::MapleLogger() << " "; - } - LogInfo::MapleLogger() << " {"; - DumpClassOrInterfaceInfo(*this, indent); - DumpFieldsAndMethods(indent, !methods.empty()); - LogInfo::MapleLogger() << "}>"; -} - void MIRTypeByName::Dump(int indent, bool dontUseName) const { const std::string &name = GlobalTables::GetStrTable().GetStringFromStrIdx(nameStrIdx); @@ -1338,12 +748,6 @@ uint32 MIRArrayType::NumberOfFieldIDs() const return fieldsNum; } -MIRStructType *MIRArrayType::EmbeddedStructType() -{ - MIRType *elemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(eTyIdx); - return elemType->EmbeddedStructType(); -} - int64 MIRArrayType::GetBitOffsetFromArrayAddress(std::vector &indexArray) { // for cases that num of dimension-operand is less than array's dimension @@ -1434,12 +838,6 @@ uint32 MIRFarrayType::NumberOfFieldIDs() const return fieldsNum; } -MIRStructType *MIRFarrayType::EmbeddedStructType() -{ - MIRType *elemType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(elemTyIdx); - return elemType->EmbeddedStructType(); -} - int64 MIRFarrayType::GetBitOffsetFromArrayAddress(int64 arrayIndex) { size_t elemsize = GetElemType()->GetSize(); @@ -1529,119 +927,6 @@ bool MIRBitFieldType::EqualTo(const MIRType &type) const return pType.fieldSize == fieldSize; } -bool MIRStructType::EqualTo(const MIRType &type) const -{ - if (type.GetKind() != typeKind) { - return false; - } - if (type.GetNameStrIdx() != nameStrIdx) { - return false; - } - - DEBUG_ASSERT(type.IsStructType(), "p is null in MIRStructType::EqualTo"); - const MIRStructType *p = static_cast(&type); - if (typeAttrs != p->typeAttrs) { - return false; - } - if (fields != p->fields) { - return false; - } - if (staticFields != p->staticFields) { - return false; - } - if (parentFields != p->parentFields) { - return false; - } - if (methods != p->methods) { - return false; - } - return true; -} - -std::string MIRStructType::GetCompactMplTypeName() const -{ - return GlobalTables::GetStrTable().GetStringFromStrIdx(nameStrIdx); -} - -MIRType *MIRStructType::GetElemType(uint32 n) const -{ - return GlobalTables::GetTypeTable().GetTypeFromTyIdx(GetElemTyIdx(n)); -} - -MIRType *MIRStructType::GetFieldType(FieldID fieldID) -{ - if (fieldID == 0) { - return this; - } - const FieldPair &fieldPair = TraverseToFieldRef(fieldID); - return GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldPair.second.first); -} - -bool MIRStructType::IsLocal() const -{ - return GlobalTables::GetGsymTable().GetStIdxFromStrIdx(nameStrIdx).Idx() != 0; -} - -std::string MIRStructType::GetMplTypeName() const -{ - std::stringstream ss; - ss << "<$"; - ss << GlobalTables::GetStrTable().GetStringFromStrIdx(nameStrIdx); - ss << ">"; - return ss.str(); -} - -bool MIRClassType::EqualTo(const MIRType &type) const -{ - if (type.GetKind() != typeKind) { - return false; - } - bool structeq = MIRStructType::EqualTo(type); - if (!structeq) { - return false; - } - - const MIRClassType &classty = static_cast(type); - // classes have parent except empty/thirdparty classes - if (parentTyIdx != classty.parentTyIdx) { - return false; - } - - if (interfacesImplemented != classty.interfacesImplemented) { - return false; - } - if (info != classty.info) { - return false; - } - if (infoIsString != classty.infoIsString) { - return false; - } - return true; -} - -bool MIRInterfaceType::EqualTo(const MIRType &type) const -{ - if (type.GetKind() != typeKind) { - return false; - } - bool structeq = MIRStructType::EqualTo(type); - if (!structeq) { - return false; - } - - const MIRInterfaceType &interfacety = static_cast(type); - if (parentsTyIdx != interfacety.parentsTyIdx) { - return false; - } - if (info != interfacety.info) { - return false; - } - if (infoIsString != interfacety.infoIsString) { - return false; - } - return true; -} - bool MIRTypeByName::EqualTo(const MIRType &type) const { return type.GetKind() == typeKind && type.GetNameStrIdx() == nameStrIdx && type.IsNameIsLocal() == nameIsLocal; @@ -1665,577 +950,6 @@ bool MIRGenericInstantType::EqualTo(const MIRType &type) const return genericTyIdx == pType.GetGenericTyIdx(); } -// in the search, curfieldid is being decremented until it reaches 1 -FieldPair MIRStructType::TraverseToFieldRef(FieldID &fieldID) const -{ - if (!fields.size()) { - return FieldPair(GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())); - } - - uint32 fieldIdx = 0; - FieldPair curPair = fields[0]; - while (fieldID > 1) { - --fieldID; - MIRType *curFieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(curPair.second.first); - MIRStructType *subStructTy = curFieldType->EmbeddedStructType(); - if (subStructTy != nullptr) { - curPair = subStructTy->TraverseToFieldRef(fieldID); - if (fieldID == 1 && curPair.second.first != TyIdx(0)) { - return curPair; - } - } - ++fieldIdx; - if (fieldIdx == fields.size()) { - return FieldPair(GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())); - } - curPair = fields[fieldIdx]; - } - return curPair; -} - -FieldPair MIRStructType::TraverseToField(FieldID fieldID) const -{ - if (fieldID >= 0) { - return TraverseToFieldRef(fieldID); - } - // in parentfields - uint32 parentFieldIdx = static_cast(-fieldID); - if (parentFields.empty() || parentFieldIdx > parentFields.size()) { - return {GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())}; - } - CHECK_FATAL(parentFieldIdx > 0, "must not be zero"); - return parentFields[parentFieldIdx - 1]; -} - -static bool TraverseToFieldInFields(const FieldVector &fields, const GStrIdx &fieldStrIdx, FieldPair &field) -{ - for (auto &fp : fields) { - if (fp.first == fieldStrIdx) { - field = fp; - return true; - } - } - return false; -} - -FieldPair MIRStructType::TraverseToField(GStrIdx fieldStrIdx) const -{ - FieldPair fieldPair; - if ((!fields.empty() && TraverseToFieldInFields(fields, fieldStrIdx, fieldPair)) || - (!staticFields.empty() && TraverseToFieldInFields(staticFields, fieldStrIdx, fieldPair)) || - TraverseToFieldInFields(parentFields, fieldStrIdx, fieldPair)) { - return fieldPair; - } - return {GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())}; -} - -bool MIRStructType::HasVolatileFieldInFields(const FieldVector &fieldsOfStruct) const -{ - for (const auto &field : fieldsOfStruct) { - if (field.second.second.GetAttr(FLDATTR_volatile) || - GlobalTables::GetTypeTable().GetTypeFromTyIdx(field.second.first)->HasVolatileField()) { - hasVolatileField = true; - return true; - } - } - hasVolatileField = false; - return false; -} - -// go through all the fields to check if there is volatile attribute set; -bool MIRStructType::HasVolatileField() const -{ - if (hasVolatileFieldSet) { - return hasVolatileField; - } - hasVolatileFieldSet = true; - return HasVolatileFieldInFields(fields) || HasVolatileFieldInFields(parentFields); -} - -int64 MIRStructType::GetBitOffsetFromUnionBaseAddr(FieldID fieldID) -{ - CHECK_FATAL(fieldID <= static_cast(NumberOfFieldIDs()), - "GetBitOffsetFromUnionBaseAddr: fieldID too large"); - if (fieldID == 0) { - return 0; - } - - FieldID curFieldID = 1; - FieldVector fieldPairs = GetFields(); - // for unions, bitfields are treated as non-bitfields - for (FieldPair field : fieldPairs) { - TyIdx fieldTyIdx = field.second.first; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - if (curFieldID == fieldID) { - // target field id is found - // offset of field in union direcly(i.e. not embedded in other struct) is zero. - return 0; - } else { - MIRStructType *subStructType = fieldType->EmbeddedStructType(); - if (subStructType == nullptr) { - // field is not a complex structure, no extra field id in it, just inc and continue to next field - curFieldID++; - } else { - // if target field id is in the embedded structure, we should go into it by recursively call - // otherwise, just add the field-id number of the embedded structure, and continue to next field - if ((curFieldID + static_cast(subStructType->NumberOfFieldIDs())) < fieldID) { - // 1 represents subStructType itself - curFieldID += static_cast(subStructType->NumberOfFieldIDs()) + 1; - } else { - return subStructType->GetBitOffsetFromBaseAddr(fieldID - curFieldID); - } - } - } - } - CHECK_FATAL(false, "GetBitOffsetFromUnionBaseAddr() fails to find field"); - return kOffsetUnknown; -} - -int64 MIRStructType::GetBitOffsetFromStructBaseAddr(FieldID fieldID) -{ - CHECK_FATAL(fieldID <= static_cast(NumberOfFieldIDs()), - "GetBitOffsetFromUnionBaseAddr: fieldID too large"); - if (fieldID == 0) { - return 0; - } - - uint64 allocedSize = 0; // space need for all fields before currentField - uint64 allocedBitSize = 0; - FieldID curFieldID = 1; - constexpr uint32 bitsPerByte = 8; // 8 bits per byte - FieldVector fieldPairs = GetFields(); - // process the struct fields - // There are 3 possible kinds of field in a MIRStructureType: - // case 1 : bitfield (including zero-width bitfield); - // case 2 : primtive field; - // case 3 : normal (empty/non-empty) structure(struct/union) field; - for (FieldPair field : fieldPairs) { - TyIdx fieldTyIdx = field.second.first; - auto fieldAttr = field.second.second; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - uint32 fieldBitSize = static_cast(fieldType)->GetFieldSize(); - size_t fieldTypeSize = fieldType->GetSize(); - uint32 fieldTypeSizeBits = static_cast(fieldTypeSize) * bitsPerByte; - auto originAlign = fieldType->GetAlign(); - uint32 fieldAlign = fieldAttr.IsPacked() ? 1 : std::min(GetTypeAttrs().GetPack(), originAlign); - auto fieldAlignBits = fieldAlign * bitsPerByte; - // case 1 : bitfield (including zero-width bitfield); - if (fieldType->GetKind() == kTypeBitField) { - fieldTypeSizeBits = static_cast(GetPrimTypeSize(fieldType->GetPrimType())) * bitsPerByte; - // Is this field is crossing the align boundary of its base type? - // for example: - // struct Expamle { - // int32 fld1 : 30 - // int32 fld2 : 3; // 30 + 3 > 32(= int32 align), cross the align boundary, start from next int32 - // boundary - // } - // - // Is field a zero-width bit field? - // Refer to C99 standard (§6.7.2.1) : - // > As a special case, a bit-field structure member with a width of 0 indicates that no further - // > bit-field is to be packed into the unit in which the previous bit-field, if any, was placed. - // - // We know that A zero-width bit field can cause the next field to be aligned on the next container - // boundary where the container is the same size as the underlying type of the bit field. - // for example: - // struct Example { - // int32 fld1 : 5 - // int32 : 0 // force the next field to be aligned on int32 align boundary - // int32 fld3 : 4 - // } - CHECK_FATAL((allocedBitSize <= UINT32_MAX - fieldBitSize), "must not be zero"); - if ((!GetTypeAttrs().IsPacked() && ((allocedBitSize / fieldTypeSizeBits) != - ((allocedBitSize + fieldBitSize - 1u) / fieldTypeSizeBits))) || - fieldBitSize == 0) { - // the field is crossing the align boundary of its base type; - // align alloced_size_in_bits to fieldAlign - allocedBitSize = RoundUp(allocedBitSize, fieldTypeSizeBits); - } - - // target field id is found - if (curFieldID == fieldID) { - return static_cast(allocedBitSize); - } else { - ++curFieldID; - } - allocedBitSize += fieldBitSize; - fieldAlignBits = (fieldAlignBits) != 0 ? fieldAlignBits : fieldTypeSizeBits; - allocedSize = std::max(allocedSize, RoundUp(allocedBitSize, fieldAlignBits) / bitsPerByte); - continue; - } // case 1 end - - bool leftOverBits = false; - uint64 offset = 0; - // no bit field before current field - if (allocedBitSize == allocedSize * bitsPerByte) { - allocedSize = RoundUp(allocedSize, fieldAlign); - offset = allocedSize; - } else { - CHECK_FATAL((allocedBitSize <= UINT32_MAX - fieldTypeSizeBits), "must not be zero"); - // still some leftover bits on allocated words, we calculate things based on bits then. - if (allocedBitSize / fieldAlignBits != (allocedBitSize + fieldTypeSizeBits - 1) / fieldAlignBits) { - // the field is crossing the align boundary of its base type - allocedBitSize = RoundUp(allocedBitSize, static_cast(fieldAlignBits)); - } - allocedSize = RoundUp(allocedSize, fieldAlign); - offset = (allocedBitSize / fieldAlignBits) * fieldAlign; - leftOverBits = true; - } - // target field id is found - if (curFieldID == fieldID) { - return static_cast(offset * bitsPerByte); - } - MIRStructType *subStructType = fieldType->EmbeddedStructType(); - // case 2 : primtive field; - if (subStructType == nullptr) { - ++curFieldID; - } else { - // case 3 : normal (empty/non-empty) structure(struct/union) field; - // if target field id is in the embedded structure, we should go into it by recursively call - // otherwise, just add the field-id number of the embedded structure, and continue to next field - if ((curFieldID + static_cast(subStructType->NumberOfFieldIDs())) < fieldID) { - curFieldID += - static_cast(subStructType->NumberOfFieldIDs()) + 1; // 1 represents subStructType itself - } else { - int64 result = subStructType->GetBitOffsetFromBaseAddr(fieldID - curFieldID); - return result + static_cast(allocedSize * bitsPerByte); - } - } - - if (leftOverBits) { - allocedBitSize += fieldTypeSizeBits; - allocedSize = - std::max(allocedSize, RoundUp(allocedBitSize, static_cast(fieldAlignBits)) / bitsPerByte); - } else { - allocedSize += fieldTypeSize; - allocedBitSize = allocedSize * bitsPerByte; - } - } - CHECK_FATAL(false, "GetBitOffsetFromStructBaseAddr() fails to find field"); - return kOffsetUnknown; -} - -int64 MIRStructType::GetBitOffsetFromBaseAddr(FieldID fieldID) -{ - CHECK_FATAL(fieldID <= static_cast(NumberOfFieldIDs()), "GetBitOffsetFromBaseAddr: fieldID too large"); - if (fieldID == 0) { - return 0; - } - switch (GetKind()) { - case kTypeClass: { - // NYI: should know class layout, for different language, the result is different - return kOffsetUnknown; // Invalid offset - } - case kTypeUnion: { - return GetBitOffsetFromUnionBaseAddr(fieldID); - } - case kTypeStruct: { - return GetBitOffsetFromStructBaseAddr(fieldID); - } - default: { - CHECK_FATAL(false, "Wrong type kind for MIRStructType!"); - } - } - CHECK_FATAL(false, "Should never reach here!"); - return kOffsetUnknown; -} - -// compute the offset of the field given by fieldID within the structure type -// structy; it returns the answer in the pair (byteoffset, bitoffset) such that -// if it is a bitfield, byteoffset gives the offset of the container for -// extracting the bitfield and bitoffset is with respect to the current byte -FieldInfo MIRStructType::GetFieldOffsetFromBaseAddr(FieldID fieldID) const -{ - CHECK_FATAL(fieldID <= static_cast(NumberOfFieldIDs()), "GetBitOffsetFromBaseAddr: fieldID too large"); - if (GetKind() == kTypeClass || fieldID == 0) { - return {0, 0}; - } - if (GetKind() == kTypeUnion || GetKind() == kTypeStruct) { - return const_cast(this)->GetFieldLayout()[fieldID - 1]; - } - CHECK_FATAL(false, "Should never reach here!"); - return {0, 0}; -} - -// Whether the memory layout of struct has paddings -bool MIRStructType::HasPadding() const -{ - size_t sumValidSize = 0; - for (uint32 i = 0; i < fields.size(); ++i) { - TyIdxFieldAttrPair pair = GetTyidxFieldAttrPair(i); - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pair.first); - if (fieldType->IsStructType() && static_cast(fieldType)->HasPadding()) { - return true; - } - sumValidSize += fieldType->GetSize(); - } - if (sumValidSize < this->GetSize()) { - return true; - } - return false; -} - -// On the ARM platform, when using both zero-sized bitfields and the pack attribute simultaneously, -// the size of a struct should be calculated according to the default alignment without the pack attribute. -bool MIRStructType::HasZeroWidthBitField() const -{ -#ifndef TARGAARCH64 - return false; -#endif - for (FieldPair field : fields) { - TyIdx fieldTyIdx = field.second.first; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - if (fieldType->GetKind() == kTypeBitField && fieldType->GetSize() == 0) { - return true; - } - } - return false; -} - -uint32 MIRStructType::GetFieldTypeAlignByFieldPair(const FieldPair &fieldPair) -{ - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldPair.second.first); - auto fieldAttr = fieldPair.second.second; - auto fieldTypeAlign = - fieldType->GetKind() == kTypeBitField ? GetPrimTypeSize(fieldType->GetPrimType()) : fieldType->GetAlign(); - auto fieldPacked = GetTypeAttrs().IsPacked() || fieldAttr.IsPacked(); - auto fieldAlign = fieldPacked ? 1u : fieldTypeAlign; - fieldAlign = fieldAttr.HasAligned() ? std::max(fieldAlign, fieldAttr.GetAlign()) : fieldAlign; - return GetTypeAttrs().HasPack() ? std::min(GetTypeAttrs().GetPack(), fieldAlign) : fieldAlign; -} - -void MIRStructType::ComputeUnionLayout() -{ - size = 0; - for (FieldPair &field : fields) { - TyIdx fieldTyIdx = field.second.first; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - MIRStructType *subStructType = fieldType->EmbeddedStructType(); - size = std::max(fieldType->GetSize(), size); - AddFieldLayout({0, 0, field}); - if (subStructType != nullptr) { - // if target field id is in the embedded structure, we should go into it by recursively call - // otherwise, just add the field-id number of the embedded structure, and continue to next field - auto &subStructFieldLayout = subStructType->GetFieldLayout(); - (void)fieldLayout.insert(fieldLayout.end(), subStructFieldLayout.begin(), subStructFieldLayout.end()); - } - } - if (GetTypeAttrs().IsTypedef()) { - size = RoundUp(size, GetTypedefOriginalAlign()); - } else { - size = RoundUp(size, GetAlign()); - } - CHECK_FATAL(fieldLayout.size() == NumberOfFieldIDs(), "fields layout != fieldID size"); - layoutComputed = true; -} - -void MIRStructType::ComputeLayout() -{ - if (layoutComputed) { - return; - } - if (GetKind() == kTypeUnion) { - ComputeUnionLayout(); - return; - } - uint32 allocedSize = 0; // space need for all fields before currentField - uint32 allocedBitSize = 0; - auto hasPack = GetTypeAttrs().HasPack(); - auto packed = GetTypeAttrs().IsPacked(); - constexpr uint8 bitsPerByte = 8; // 8 bits per byte - for (FieldPair &fieldPair : fields) { - auto tyIdxFieldAttrPair = fieldPair.second; - TyIdx fieldTyIdx = tyIdxFieldAttrPair.first; - auto fieldAttr = tyIdxFieldAttrPair.second; - MIRType *fieldType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(fieldTyIdx); - auto fieldPacked = packed || fieldAttr.IsPacked(); - uint32 fieldAlign = GetFieldTypeAlignByFieldPair(fieldPair); - uint32 fieldAlignBits = fieldAlign * bitsPerByte; - uint32 fieldBitSize; - uint32 fieldTypeSize = static_cast(fieldType->GetSize()); - uint32 fieldTypeSizeBits = fieldTypeSize * bitsPerByte; - // case 1 : bitfield (including zero-width bitfield); - if (fieldType->GetKind() == kTypeBitField) { - fieldBitSize = static_cast(fieldType)->GetFieldSize(); - fieldTypeSizeBits = static_cast(GetPrimTypeSize(fieldType->GetPrimType())) * bitsPerByte; - // zero bit field - CHECK_FATAL((allocedBitSize <= UINT32_MAX - fieldBitSize), "must not be zero"); - if (fieldAttr.HasAligned()) { - if ((fieldAttr.GetAlign() < fieldAlign && - fieldAttr.GetAlign() <= ((fieldTypeSizeBits - fieldBitSize) / bitsPerByte))) { - allocedBitSize = RoundUp(allocedBitSize, fieldAttr.GetAlign() * bitsPerByte); - } else { - allocedBitSize = RoundUp(allocedBitSize, fieldAlignBits); - } - } else if ((!hasPack && !fieldPacked && - ((allocedBitSize / fieldTypeSizeBits) != - ((allocedBitSize + fieldBitSize - 1u) / fieldTypeSizeBits))) || - fieldBitSize == 0) { - // the field is crossing the align boundary of its base type; - // align alloced_size_in_bits to fieldAlign - allocedBitSize = RoundUp(allocedBitSize, fieldTypeSizeBits); - } - auto info = - FieldInfo((allocedBitSize / fieldAlignBits) * fieldAlign, allocedBitSize % fieldAlignBits, fieldPair); - AddFieldLayout(info); - allocedBitSize += fieldBitSize; - fieldAlignBits = (fieldAlignBits) != 0 ? fieldAlignBits : fieldTypeSizeBits; - allocedSize = - std::max(allocedSize, static_cast(RoundUp(allocedBitSize, fieldAlignBits) / bitsPerByte)); - continue; - } // case 1 end - - bool leftOverBits = false; - uint32 offset = 0; - // no bit field before current field - if (allocedBitSize == allocedSize * bitsPerByte) { - allocedSize = RoundUp(allocedSize, fieldAlign); - offset = allocedSize; - } else { - CHECK_FATAL((allocedBitSize <= UINT32_MAX - fieldTypeSizeBits), "must not be zero"); - // still some leftover bits on allocated words, we calculate things based on bits then. - if ((allocedBitSize / fieldAlignBits != (allocedBitSize + fieldTypeSizeBits - 1) / fieldAlignBits) || - fieldTypeSize == 0) { - // the field is crossing the align boundary of its base type - allocedBitSize = RoundUp(allocedBitSize, static_cast(fieldAlignBits)); - } - allocedSize = RoundUp(allocedSize, fieldAlign); - offset = (allocedBitSize / fieldAlignBits) * fieldAlign; - leftOverBits = true; - } - // target field id is found - MIRStructType *subStructType = fieldType->EmbeddedStructType(); - // case 2 : primitive field; - AddFieldLayout({offset, 0, fieldPair}); - if (subStructType != nullptr) { - // case 3 : normal (empty/non-empty) structure(struct/union) field; - // if target field id is in the embedded structure, we should go into it by recursively call - // otherwise, just add the field-id number of the embedded structure, and continue to next field - auto &subStructFieldOffsets = subStructType->GetFieldLayout(); - for (FieldInfo layout : subStructFieldOffsets) { - auto convertedLayout = layout; - convertedLayout.byteOffset += offset; - AddFieldLayout(convertedLayout); - } - } - if (leftOverBits) { - allocedBitSize += fieldTypeSizeBits; - allocedSize = - std::max(allocedSize, static_cast(RoundUp(allocedBitSize, fieldAlignBits) / bitsPerByte)); - } else if (!static_cast(fieldType)->IsIncompleteArray()) { - allocedSize += fieldTypeSize; - allocedBitSize = allocedSize * bitsPerByte; - } - } - if (GetTypeAttrs().IsTypedef()) { - allocedSize = RoundUp(allocedSize, GetTypedefOriginalAlign()); - } else { - allocedSize = RoundUp(allocedSize, GetAlign()); - } - size = allocedSize; - CHECK_FATAL(fieldLayout.size() == NumberOfFieldIDs(), "fields layout != fieldID size"); - layoutComputed = true; -} - -// set hasVolatileField to true if parent type has volatile field, otherwise flase. -static bool ParentTypeHasVolatileField(const TyIdx parentTyIdx, bool &hasVolatileField) -{ - hasVolatileField = (GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)->HasVolatileField()); - return hasVolatileField; -} - -// go through all the fields to check if there is volatile attribute set; -bool MIRClassType::HasVolatileField() const -{ - return MIRStructType::HasVolatileField() || - (parentTyIdx != 0u && ParentTypeHasVolatileField(parentTyIdx, hasVolatileField)); -} - -// go through all the fields to check if there is volatile attribute set; -bool MIRInterfaceType::HasVolatileField() const -{ - if (MIRStructType::HasVolatileField()) { - return true; - } - for (TyIdx parentTypeIdx : parentsTyIdx) { - if (ParentTypeHasVolatileField(parentTypeIdx, hasVolatileField)) { - return true; - } - } - return false; -} - -bool MIRStructType::HasTypeParamInFields(const FieldVector &fieldsOfStruct) const -{ - for (const FieldPair &field : fieldsOfStruct) { - if (field.second.second.GetAttr(FLDATTR_generic)) { - return true; - } - } - return false; -} - -// go through all the fields to check if there is generic attribute set; -bool MIRStructType::HasTypeParam() const -{ - return HasTypeParamInFields(fields) || HasTypeParamInFields(parentFields); -} - -bool MIRClassType::HasTypeParam() const -{ - return MIRStructType::HasTypeParam() || - (parentTyIdx != 0u && GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)->HasTypeParam()); -} - -bool MIRInterfaceType::HasTypeParam() const -{ - if (MIRStructType::HasTypeParam()) { - return true; - } - // check if the parent classes have type parameter - for (TyIdx parentTypeIdx : parentsTyIdx) { - if (GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTypeIdx)->HasTypeParam()) { - return true; - } - } - return false; -} - -uint32 MIRClassType::NumberOfFieldIDs() const -{ - if (fieldsNum != kInvalidFieldNum) { - return fieldsNum; - } - size_t parentFieldIDs = 0; - if (parentTyIdx != TyIdx(0)) { - MIRType *parentty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx); - parentFieldIDs = parentty->NumberOfFieldIDs(); - } - fieldsNum = parentFieldIDs + MIRStructType::NumberOfFieldIDs(); - return fieldsNum; -} - -FieldPair MIRClassType::TraverseToFieldRef(FieldID &fieldID) const -{ - if (parentTyIdx != 0u) { - auto *parentClassType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(parentTyIdx)); - if (parentClassType != nullptr) { - --fieldID; - const FieldPair &curPair = parentClassType->TraverseToFieldRef(fieldID); - if (fieldID == 1 && curPair.second.first != 0u) { - return curPair; - } - } - } - return MIRStructType::TraverseToFieldRef(fieldID); -} - -// fields in interface are all static and are global, won't be accessed through fields -FieldPair MIRInterfaceType::TraverseToFieldRef(FieldID &fieldID) const -{ - return {GStrIdx(0), TyIdxFieldAttrPair(TyIdx(0), FieldAttrs())}; -} - bool MIRPtrType::IsPointedTypeVolatile(int fieldID) const { if (typeAttrs.GetAttr(ATTR_volatile)) { @@ -2272,25 +986,6 @@ uint32 MIRPtrType::GetAlign() const return GetPointerSize(); } -TyIdxFieldAttrPair MIRPtrType::GetPointedTyIdxFldAttrPairWithFieldID(FieldID fldId) const -{ - if (fldId == 0) { - return TyIdxFieldAttrPair(pointedTyIdx, FieldAttrs()); - } - MIRType *ty = GlobalTables::GetTypeTable().GetTypeFromTyIdx(pointedTyIdx); - MIRStructType *structTy = ty->EmbeddedStructType(); - if (structTy == nullptr) { - // this can happen due to casting in C; just return the pointed to type - return TyIdxFieldAttrPair(pointedTyIdx, FieldAttrs()); - } - return structTy->TraverseToField(fldId).second; -} - -TyIdx MIRPtrType::GetPointedTyIdxWithFieldID(FieldID fieldID) const -{ - return GetPointedTyIdxFldAttrPairWithFieldID(fieldID).first; -} - std::string MIRPtrType::GetMplTypeName() const { std::stringstream ss; @@ -2324,20 +1019,6 @@ MIRFuncType *MIRPtrType::GetPointedFuncType() const return nullptr; } -uint32 MIRStructType::NumberOfFieldIDs() const -{ - if (fieldsNum != kInvalidFieldNum) { - return fieldsNum; - } - fieldsNum = 0; - for (FieldPair curpair : fields) { - ++fieldsNum; - MIRType *curfieldtype = GlobalTables::GetTypeTable().GetTypeFromTyIdx(curpair.second.first); - fieldsNum += curfieldtype->NumberOfFieldIDs(); - } - return fieldsNum; -} - TypeAttrs FieldAttrs::ConvertToTypeAttrs() { TypeAttrs attr; @@ -2395,62 +1076,6 @@ bool IsSameHomogeneousAggregatesBaseType(PrimType type, PrimType nextType) return false; } -bool IsUnionHomogeneousAggregates(const MIRStructType &ty, PrimType &primType, size_t &elemNum) -{ - primType = PTY_begin; - elemNum = 0; - for (const auto &field : ty.GetFields()) { - MIRType *filedType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(field.second.first); - if (filedType->GetSize() == 0) { - continue; - } - PrimType filedPrimType = PTY_begin; - size_t filedElemNum = 0; - if (!IsHomogeneousAggregates(*filedType, filedPrimType, filedElemNum, false)) { - return false; - } - primType = (primType == PTY_begin) ? filedPrimType : primType; - if (!IsSameHomogeneousAggregatesBaseType(primType, filedPrimType)) { - return false; - } - elemNum = std::max(elemNum, filedElemNum); - } - return (ty.GetSize() == static_cast(GetPrimTypeSize(primType) * elemNum)); -} - -bool IsStructHomogeneousAggregates(const MIRStructType &ty, PrimType &primType, size_t &elemNum) -{ - primType = PTY_begin; - elemNum = 0; - FieldID fieldsNum = 0; - - for (const auto &field : ty.GetFields()) { - ++fieldsNum; - MIRType *filedType = GlobalTables::GetTypeTable().GetTypeFromTyIdx(field.second.first); - if (elemNum != 0 && primType != PTY_begin) { - uint32 curOffset = static_cast(GetPrimTypeSize(primType) * elemNum); - if (curOffset != ty.GetFieldOffsetFromBaseAddr(fieldsNum).byteOffset) { - return false; - } - } - fieldsNum += static_cast(filedType->NumberOfFieldIDs()); - if (filedType->GetSize() == 0) { - continue; - } - PrimType filedPrimType = PTY_begin; - size_t filedElemNum = 0; - if (!IsHomogeneousAggregates(*filedType, filedPrimType, filedElemNum, false)) { - return false; - } - elemNum += filedElemNum; - primType = (primType == PTY_begin) ? filedPrimType : primType; - if (elemNum > kMaxHfaOrHvaElemNumber || !IsSameHomogeneousAggregatesBaseType(primType, filedPrimType)) { - return false; - } - } - return (ty.GetSize() == static_cast(GetPrimTypeSize(primType) * elemNum)); -} - bool IsArrayHomogeneousAggregates(const MIRArrayType &ty, PrimType &primType, size_t &elemNum) { primType = PTY_begin; @@ -2469,21 +1094,12 @@ bool IsArrayHomogeneousAggregates(const MIRArrayType &ty, PrimType &primType, si bool IsHomogeneousAggregates(const MIRType &ty, PrimType &primType, size_t &elemNum, bool firstDepth) { - if (firstDepth && ty.GetKind() == kTypeUnion) { - return IsUnionHomogeneousAggregates(static_cast(ty), primType, elemNum); - } - if (firstDepth && ty.GetKind() != kTypeStruct) { + if (firstDepth) { return false; } primType = PTY_begin; elemNum = 0; - if (ty.GetKind() == kTypeStruct) { - auto &structType = static_cast(ty); - return IsStructHomogeneousAggregates(structType, primType, elemNum); - } else if (ty.GetKind() == kTypeUnion) { - auto &unionType = static_cast(ty); - return IsUnionHomogeneousAggregates(unionType, primType, elemNum); - } else if (ty.GetKind() == kTypeArray) { + if (ty.GetKind() == kTypeArray) { auto &arrType = static_cast(ty); return IsArrayHomogeneousAggregates(arrType, primType, elemNum); } else { @@ -2505,26 +1121,11 @@ bool IsParamStructCopyToMemory(const MIRType &ty) } return false; } - -bool IsReturnInMemory(const MIRType &ty) -{ - if (ty.GetPrimType() == PTY_agg) { - PrimType primType = PTY_begin; - size_t elemNum = 0; - return !IsHomogeneousAggregates(ty, primType, elemNum) && ty.GetSize() > k16BitSize; - } - return false; -} #else bool IsParamStructCopyToMemory(const MIRType &ty) { return ty.GetPrimType() == PTY_agg && ty.GetSize() > k16BitSize; } - -bool IsReturnInMemory(const MIRType &ty) -{ - return ty.GetPrimType() == PTY_agg && ty.GetSize() > k16BitSize; -} #endif // TARGAARCH64 } // namespace maple #endif // MIR_FEATURE_FULL diff --git a/ecmascript/compiler/codegen/maple/maple_me/include/orig_symbol.h b/ecmascript/compiler/codegen/maple/maple_me/include/orig_symbol.h index 00b31f952a..a58e6f194a 100644 --- a/ecmascript/compiler/codegen/maple/maple_me/include/orig_symbol.h +++ b/ecmascript/compiler/codegen/maple/maple_me/include/orig_symbol.h @@ -91,21 +91,6 @@ public: if (typeAttr.GetAttr(ATTR_oneelem_simd)) { return true; } - if (fieldID != 0) { - auto type = GlobalTables::GetTypeTable().GetTypeFromTyIdx(symOrPreg.mirSt->GetTyIdx()); - if (type->IsMIRArrayType()) { - type = static_cast(type)->GetElemType(); - } - if (!type->IsMIRStructType()) { - return false; - } - MIRStructType *structType = static_cast( - GlobalTables::GetTypeTable().GetTypeFromTyIdx(symOrPreg.mirSt->GetTyIdx())); - FieldAttrs fattrs = structType->GetFieldAttrs(fieldID); - if (fattrs.GetAttr(FLDATTR_oneelem_simd)) { - return true; - } - } } return false; } diff --git a/ecmascript/compiler/codegen/maple/mpl2mpl/src/constantfold.cpp b/ecmascript/compiler/codegen/maple/mpl2mpl/src/constantfold.cpp index ad8f868edc..9b3c17bbed 100644 --- a/ecmascript/compiler/codegen/maple/mpl2mpl/src/constantfold.cpp +++ b/ecmascript/compiler/codegen/maple/mpl2mpl/src/constantfold.cpp @@ -1395,13 +1395,6 @@ static bool ExtractbitsRedundant(const ExtractbitsNode &x, MIRFunction &f) MIRSymbol *sym = f.GetLocalOrGlobalSymbol(dread->GetStIdx()); ASSERT_NOT_NULL(sym); mirType = sym->GetType(); - if (dread->GetFieldID() != 0) { - MIRStructType *structType = dynamic_cast(mirType); - if (structType == nullptr) { - return false; - } - mirType = structType->GetFieldType(dread->GetFieldID()); - } } else if (opnd->GetOpCode() == OP_iread) { IreadNode *iread = static_cast(opnd); MIRPtrType *ptrType = @@ -1410,13 +1403,6 @@ static bool ExtractbitsRedundant(const ExtractbitsNode &x, MIRFunction &f) return false; } mirType = ptrType->GetPointedType(); - if (iread->GetFieldID() != 0) { - MIRStructType *structType = dynamic_cast(mirType); - if (structType == nullptr) { - return false; - } - mirType = structType->GetFieldType(iread->GetFieldID()); - } } else if (opnd->GetOpCode() == OP_extractbits && x.GetBitsSize() > static_cast(opnd)->GetBitsSize()) { return (x.GetOpCode() == OP_zext && x.GetPrimType() == opnd->GetPrimType() && @@ -1488,10 +1474,6 @@ std::pair> ConstantFold::FoldIread(IreadNode *n TyIdx typeId = msy->GetTyIdx(); CHECK_FATAL(!GlobalTables::GetTypeTable().GetTypeTable().empty(), "container check"); MIRType *msyType = GlobalTables::GetTypeTable().GetTypeTable()[typeId]; - if (addrofNode->GetFieldID() != 0) { - CHECK_FATAL(msyType->IsStructType(), "must be"); - msyType = static_cast(msyType)->GetFieldType(addrofNode->GetFieldID()); - } MIRPtrType *ptrType = static_cast(GlobalTables::GetTypeTable().GetTypeFromTyIdx(node->GetTyIdx())); // If the high level type of iaddrof/iread doesn't match // the type of addrof's rhs, this optimization cannot be done.