diff --git a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h index fe657e0f57275977ddf0ea6ec74348d6a2199506..5b558b9b3de47abac6d322ff89fa5cc897e309e7 100644 --- a/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h +++ b/src/mapleall/maple_be/include/cg/aarch64/aarch64_cgfunc.h @@ -115,6 +115,7 @@ class AArch64CGFunc : public CGFunc { void SelectIcall(IcallNode &icallNode, Operand &fptrOpnd) override; void SelectIntrinCall(IntrinsiccallNode &intrinsicCallNode) override; Operand *SelectIntrinsicOpWithOneParam(IntrinsicopNode &intrinopNode, std::string name) override; + Operand *SelectIntrinsicOpWithNParams(IntrinsicopNode &intrinopNode, PrimType retType, std::string name) override; Operand *SelectCclz(IntrinsicopNode &intrinopNode) override; Operand *SelectCctz(IntrinsicopNode &intrinopNode) override; Operand *SelectCpopcount(IntrinsicopNode &intrinopNode) override; @@ -237,7 +238,7 @@ class AArch64CGFunc : public CGFunc { RegOperand &SelectCopy(Operand &src, PrimType stype, PrimType dtype) override; void SelectCopy(Operand &dest, PrimType dtype, Operand &src, PrimType stype); void SelectCopyImm(Operand &dest, ImmOperand &src, PrimType dtype); - void SelectLibCall(const std::string&, std::vector&, PrimType, PrimType, bool is2ndRet = false); + void SelectLibCall(const std::string&, std::vector&, std::vector, bool is2ndRet = false); Operand &GetTargetRetOperand(PrimType primType, int32 sReg) override; Operand &GetOrCreateRflag() override; const Operand *GetRflag() const override; diff --git a/src/mapleall/maple_be/include/cg/cgfunc.h b/src/mapleall/maple_be/include/cg/cgfunc.h index a4d023136a2b8d48c23dadd299a6623ffbb1b705..dd113bea62af78f7d3529fd19b039d56e2fd5464 100644 --- a/src/mapleall/maple_be/include/cg/cgfunc.h +++ b/src/mapleall/maple_be/include/cg/cgfunc.h @@ -178,6 +178,7 @@ class CGFunc { virtual void SelectIcall(IcallNode &icallNode, Operand &fptrOpnd) = 0; virtual void SelectIntrinCall(IntrinsiccallNode &intrinsiccallNode) = 0; virtual Operand *SelectIntrinsicOpWithOneParam(IntrinsicopNode &intrinopNode, std::string name) = 0; + virtual Operand *SelectIntrinsicOpWithNParams(IntrinsicopNode &intrinopNode, PrimType retType, std::string name) = 0; virtual Operand *SelectCclz(IntrinsicopNode &intrinopNode) = 0; virtual Operand *SelectCctz(IntrinsicopNode &intrinopNode) = 0; virtual Operand *SelectCpopcount(IntrinsicopNode &intrinopNode) = 0; diff --git a/src/mapleall/maple_be/src/be/lower.cpp b/src/mapleall/maple_be/src/be/lower.cpp index 12dadad412b6597e4032191df6c8915705d87266..6345513aff01d082d83e3fc5f8fd367ecaad1c3d 100644 --- a/src/mapleall/maple_be/src/be/lower.cpp +++ b/src/mapleall/maple_be/src/be/lower.cpp @@ -3497,6 +3497,16 @@ bool CGLowerer::IsIntrinsicOpHandledAtLowerLevel(MIRIntrinsicID intrinsic) { case INTRN_C___sync_lock_release_8: case INTRN_C___sync_lock_release_4: case INTRN_C__builtin_return_address: + case INTRN_C_strcpy: + case INTRN_C_strncpy: + case INTRN_C_strchr: + case INTRN_C_memcmp: + case INTRN_C_memcpy: + case INTRN_C_memset: + case INTRN_C_strlen: + case INTRN_C_strcmp: + case INTRN_C_strncmp: + case INTRN_C_memmove: return true; #endif default: diff --git a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp index 8d92320022a55069662690b2450e94a23a20e362..4b1695465118353f7e5d2bbe4cc16d2f79b69460 100644 --- a/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/aarch64/aarch64_cgfunc.cpp @@ -1530,6 +1530,7 @@ void AArch64CGFunc::SelectAggDassign(DassignNode &stmt) { if (lhsSize > kParmMemcpySize) { std::vector opndVec; RegOperand *regResult = &CreateVirtualRegisterOperand(NewVReg(kRegTyInt, k8ByteSize)); + #define NUM_OF_OPERANDS 4 opndVec.push_back(regResult); /* result */ opndVec.push_back(PrepareMemcpyParamOpnd(lhsIsLo12, *lhsSymbol, lhsOffsetVal, *lhsBaseReg)); /* param 0 */ @@ -1538,7 +1539,9 @@ void AArch64CGFunc::SelectAggDassign(DassignNode &stmt) { opndVec.push_back(PrepareMemcpyParamOpnd(lhsSize)); /* param 2 */ - SelectLibCall("memcpy", opndVec, PTY_a64, PTY_a64); + std::vector opndTypes(NUM_OF_OPERANDS, PTY_a64); + + SelectLibCall("memcpy", opndVec, opndTypes); return; } @@ -1651,6 +1654,7 @@ void AArch64CGFunc::SelectAggDassign(DassignNode &stmt) { if (lhsSize > kParmMemcpySize) { std::vector opndVec; RegOperand *regResult = &CreateVirtualRegisterOperand(NewVReg(kRegTyInt, k8ByteSize)); + #define NUM_OF_OPERANDS 4 opndVec.push_back(regResult); /* result */ opndVec.push_back(PrepareMemcpyParamOpnd(lhsIsLo12, *lhsSymbol, lhsOffsetVal, *lhsBaseReg)); /* param 0 */ @@ -1659,7 +1663,9 @@ void AArch64CGFunc::SelectAggDassign(DassignNode &stmt) { opndVec.push_back(PrepareMemcpyParamOpnd(lhsSize)); /* param 2 */ - SelectLibCall("memcpy", opndVec, PTY_a64, PTY_a64); + std::vector opndTypes(NUM_OF_OPERANDS, PTY_a64); + + SelectLibCall("memcpy", opndVec, opndTypes); return; } @@ -2027,6 +2033,7 @@ void AArch64CGFunc::SelectAggIassign(IassignNode &stmt, Operand &AddrOpnd) { if (lhsSize > kParmMemcpySize) { std::vector opndVec; RegOperand *regResult = &CreateVirtualRegisterOperand(NewVReg(kRegTyInt, k8ByteSize)); + #define NUM_OF_OPERANDS 4 opndVec.push_back(regResult); /* result */ opndVec.push_back(PrepareMemcpyParamOpnd(static_cast(lhsOffset), lhsAddrOpnd)); /* param 0 */ @@ -2035,7 +2042,9 @@ void AArch64CGFunc::SelectAggIassign(IassignNode &stmt, Operand &AddrOpnd) { opndVec.push_back(PrepareMemcpyParamOpnd(lhsSize)); /* param 2 */ - SelectLibCall("memcpy", opndVec, PTY_a64, PTY_a64); + std::vector opndTypes(NUM_OF_OPERANDS, PTY_a64); + + SelectLibCall("memcpy", opndVec, opndTypes); return; } @@ -2163,6 +2172,7 @@ void AArch64CGFunc::SelectAggIassign(IassignNode &stmt, Operand &AddrOpnd) { if (lhsSize > kParmMemcpySize) { std::vector opndVec; RegOperand *regResult = &CreateVirtualRegisterOperand(NewVReg(kRegTyInt, k8ByteSize)); + #define NUM_OF_OPERANDS 4 opndVec.push_back(regResult); /* result */ opndVec.push_back(PrepareMemcpyParamOpnd(static_cast(lhsOffset), lhsAddrOpnd)); /* param 0 */ @@ -2171,7 +2181,9 @@ void AArch64CGFunc::SelectAggIassign(IassignNode &stmt, Operand &AddrOpnd) { opndVec.push_back(PrepareMemcpyParamOpnd(lhsSize)); /* param 2 */ - SelectLibCall("memcpy", opndVec, PTY_a64, PTY_a64); + std::vector opndTypes(NUM_OF_OPERANDS, PTY_a64); + + SelectLibCall("memcpy", opndVec, opndTypes); return; } @@ -4635,13 +4647,47 @@ Operand *AArch64CGFunc::SelectIntrinsicOpWithOneParam(IntrinsicopNode &intrnNode } std::vector opndVec; RegOperand *dst = &CreateRegisterOperandOfType(ptype); + #define NUM_OF_OPERANDS 2 opndVec.push_back(dst); /* result */ opndVec.push_back(opnd); /* param 0 */ - SelectLibCall(name, opndVec, ptype, ptype); + + std::vector opndTypes(NUM_OF_OPERANDS, ptype); + + SelectLibCall(name, opndVec, opndTypes); return dst; } +Operand *AArch64CGFunc::SelectIntrinsicOpWithNParams(IntrinsicopNode &intrnNode, PrimType retType, std::string name) { + MapleVector argNodes = intrnNode.GetNopnd(); + //FATAL(argNodes.size() > 0, "Faild to process intrinsic with zero params by NParams func"); + + std::vector opndVec; + std::vector opndTypes; + RegOperand *retOpnd = &CreateRegisterOperandOfType(retType); + opndVec.push_back(retOpnd); + opndTypes.push_back(retType); + + for (BaseNode* argexpr : argNodes) { + PrimType ptype = argexpr->GetPrimType(); + Operand *opnd = HandleExpr(intrnNode, *argexpr); + + if (opnd->IsMemoryAccessOperand()) { + RegOperand &ldDest = CreateRegisterOperandOfType(ptype); + Insn &insn = GetCG()->BuildInstruction(PickLdInsn(GetPrimTypeBitSize(ptype), ptype), ldDest, *opnd); + GetCurBB()->AppendInsn(insn); + opnd = &ldDest; + } + + opndVec.push_back(opnd); + opndTypes.push_back(ptype); + } + + SelectLibCall(name, opndVec, opndTypes); + + return retOpnd; +} + /* According to gcc.target/aarch64/ffs.c */ Operand *AArch64CGFunc::SelectAArch64ffs(Operand &argOpnd, PrimType argType) { RegOperand &destOpnd = LoadIntoRegister(argOpnd, argType); @@ -4688,7 +4734,10 @@ Operand *AArch64CGFunc::SelectRoundLibCall(RoundType roundType, const TypeCvtNod } else { libName.assign(is64Bits ? "round" : "roundf"); } - SelectLibCall(libName, opndVec, ftype, rtype); + + std::vector opndTypes{rtype, ftype}; + + SelectLibCall(libName, opndVec, opndTypes); return resOpnd; } @@ -5234,7 +5283,9 @@ Operand *AArch64CGFunc::SelectMalloc(UnaryNode &node, Operand &opnd0) { } Operand &opnd1 = CreateImmOperand(1, srcPty, false); opndVec.emplace_back(&opnd1); - SelectLibCall(funcName, opndVec, srcPty, retType); + std::vector opndTypes{retType, srcPty, srcPty}; + + SelectLibCall(funcName, opndVec, opndTypes); return &resOpnd; } @@ -5256,7 +5307,9 @@ Operand *AArch64CGFunc::SelectGCMalloc(GCMallocNode &node) { std::vector opndVec{ &resOpnd, &opndSize, &opndAlign }; const std::string &funcName = "MCC_NewObj"; - SelectLibCall(funcName, opndVec, PTY_u64, retType); + std::vector opndTypes{retType, PTY_u64, PTY_u64}; + + SelectLibCall(funcName, opndVec, opndTypes); return &resOpnd; } @@ -5292,9 +5345,10 @@ Operand *AArch64CGFunc::SelectJarrayMalloc(JarrayMallocNode &node, Operand &opnd RegOperand &resOpnd = CreateRegisterOperandOfType(retType); std::vector opndVec{ &resOpnd, &opndFixedSize, &opndElemSize, opndNElems64, &opndAlign }; + std::vector opndTypes{ retType, PTY_u64, PTY_u64, PTY_u64, PTY_u64 }; const std::string &funcName = "MCC_NewObj_flexible"; - SelectLibCall(funcName, opndVec, PTY_u64, retType); + SelectLibCall(funcName, opndVec, opndTypes); /* Generate the store of the object length field */ MemOperand &opndArrayLengthField = CreateMemOpnd(resOpnd, AArch64RTSupport::kArrayLengthOffset, k4BitSize); @@ -6467,8 +6521,10 @@ void AArch64CGFunc::CreateCallStructParamMemcpy(const MIRSymbol *sym, RegOperand AArch64ImmOperand &sizeOpnd = CreateImmOperand(structSize, k64BitSize, false); GetCurBB()->AppendInsn(GetCG()->BuildInstruction(MOP_xmovri32, vreg3, sizeOpnd)); opndVec.push_back(&vreg3); /* param 2 */ + #define NUM_OF_OPERANDS 4 + std::vector opndTypes(NUM_OF_OPERANDS, PTY_a64); - SelectLibCall("memcpy", opndVec, PTY_a64, PTY_a64); + SelectLibCall("memcpy", opndVec, opndTypes); } AArch64RegOperand *AArch64CGFunc::CreateCallStructParamCopyToStack(uint32 numMemOp, MIRSymbol *sym, RegOperand *addrOpd, @@ -7809,8 +7865,8 @@ Operand &AArch64CGFunc::GetOrCreatevaryreg() { } /* the first operand in opndvec is return opnd */ -void AArch64CGFunc::SelectLibCall(const std::string &funcName, std::vector &opndVec, PrimType primType, - PrimType retPrimType, bool is2ndRet) { +void AArch64CGFunc::SelectLibCall(const std::string &funcName, std::vector &opndVec, + std::vector opndTypes, bool is2ndRet) { MIRSymbol *st = GlobalTables::GetGsymTable().CreateSymbol(kScopeGlobal); st->SetNameStrIdx(funcName); st->SetStorageClass(kScExtern); @@ -7818,12 +7874,13 @@ void AArch64CGFunc::SelectLibCall(const std::string &funcName, std::vector vec; std::vector vecAt; + //FATAL(opndVec.size() == opndTypes.size(), ""); for (size_t i = 1; i < opndVec.size(); ++i) { - vec.emplace_back(GlobalTables::GetTypeTable().GetTypeTable()[static_cast(primType)]->GetTypeIndex()); + vec.emplace_back(GlobalTables::GetTypeTable().GetTypeTable()[static_cast(opndTypes[i])]->GetTypeIndex()); vecAt.emplace_back(TypeAttrs()); } - MIRType *retType = GlobalTables::GetTypeTable().GetTypeTable().at(static_cast(primType)); + MIRType *retType = GlobalTables::GetTypeTable().GetTypeTable().at(static_cast(opndTypes[0])); st->SetTyIdx(GetBecommon().BeGetOrCreateFunctionType(retType->GetTypeIndex(), vec, vecAt)->GetTypeIndex()); if (GetCG()->GenerateVerboseCG()) { @@ -7833,22 +7890,22 @@ void AArch64CGFunc::SelectLibCall(const std::string &funcName, std::vectorNew(*GetFuncScopeAllocator()); for (size_t i = 1; i < opndVec.size(); ++i) { MIRType *ty; - ty = GlobalTables::GetTypeTable().GetTypeTable()[static_cast(primType)]; + ty = GlobalTables::GetTypeTable().GetTypeTable()[static_cast(opndTypes[i])]; Operand *stOpnd = opndVec[i]; if (stOpnd->GetKind() != Operand::kOpdRegister) { - stOpnd = &SelectCopy(*stOpnd, primType, primType); + stOpnd = &SelectCopy(*stOpnd, opndTypes[i], opndTypes[i]); } RegOperand *expRegOpnd = static_cast(stOpnd); parmLocator.LocateNextParm(*ty, ploc); if (ploc.reg0 != 0) { /* load to the register */ AArch64RegOperand &parmRegOpnd = - GetOrCreatePhysicalRegisterOperand(ploc.reg0, expRegOpnd->GetSize(), GetRegTyFromPrimTy(primType)); - SelectCopy(parmRegOpnd, primType, *expRegOpnd, primType); + GetOrCreatePhysicalRegisterOperand(ploc.reg0, expRegOpnd->GetSize(), GetRegTyFromPrimTy(opndTypes[i])); + SelectCopy(parmRegOpnd, opndTypes[i], *expRegOpnd, opndTypes[i]); srcOpnds->PushOpnd(parmRegOpnd); } ASSERT(ploc.reg1 == 0, "SelectCall NYI"); @@ -7856,7 +7913,7 @@ void AArch64CGFunc::SelectLibCall(const std::string &funcName, std::vectorGetStIdx(), false); Insn &callInsn = AppendCall(*sym, *srcOpnds); - MIRType *callRetType = GlobalTables::GetTypeTable().GetTypeTable().at(static_cast(retPrimType)); + MIRType *callRetType = GlobalTables::GetTypeTable().GetTypeTable().at(static_cast(opndTypes[0])); if (callRetType != nullptr) { callInsn.SetRetSize(callRetType->GetSize()); callInsn.SetIsCallReturnUnsigned(IsUnsignedInteger(callRetType->GetPrimType())); @@ -7864,7 +7921,7 @@ void AArch64CGFunc::SelectLibCall(const std::string &funcName, std::vectorGetRegisterNumber() != regNum) { AArch64RegOperand &retOpnd = GetOrCreatePhysicalRegisterOperand(regNum, regOpnd->GetSize(), - GetRegTyFromPrimTy(retPrimType)); - SelectCopy(*opnd0, retPrimType, retOpnd, retPrimType); + GetRegTyFromPrimTy(opndTypes[0])); + SelectCopy(*opnd0, opndTypes[0], retOpnd, opndTypes[0]); } } diff --git a/src/mapleall/maple_be/src/cg/cgfunc.cpp b/src/mapleall/maple_be/src/cg/cgfunc.cpp index 7e51397b40180972b3b571847650bb708b17c718..94f3fd93dfb6778010e88ed0522dbd211b92a984 100644 --- a/src/mapleall/maple_be/src/cg/cgfunc.cpp +++ b/src/mapleall/maple_be/src/cg/cgfunc.cpp @@ -635,6 +635,26 @@ Operand *HandleIntrinOp(const BaseNode &parent, BaseNode &expr, CGFunc &cgFunc) return cgFunc.SelectCSyncLockRelease(intrinsicopNode, PTY_i64); case INTRN_C__builtin_return_address: return cgFunc.SelectCReturnAddress(intrinsicopNode); + case INTRN_C_strcpy: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_a64, "strcpy"); + case INTRN_C_strncpy: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_a64, "strncpy"); + case INTRN_C_strchr: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_a64, "strchr"); + case INTRN_C_memcmp: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_i32, "memcmp"); + case INTRN_C_memcpy: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_a64, "memcpy"); + case INTRN_C_memset: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_a64, "memset"); + case INTRN_C_strlen: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_a64, "strlen"); + case INTRN_C_strcmp: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_i32, "strcmp"); + case INTRN_C_strncmp: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_i32, "strncmp"); + case INTRN_C_memmove: + return cgFunc.SelectIntrinsicOpWithNParams(intrinsicopNode, PTY_a64, "memmove"); case INTRN_vector_sum_v8u8: case INTRN_vector_sum_v8i8: case INTRN_vector_sum_v4u16: case INTRN_vector_sum_v4i16: case INTRN_vector_sum_v2u32: case INTRN_vector_sum_v2i32: diff --git a/src/mapleall/maple_ir/include/intrinsic_c.def b/src/mapleall/maple_ir/include/intrinsic_c.def index 343f18af9bf98820dcd37390a976b38ebc8ed27c..a67884515abd2330986749c63bd7163ed7f31e3f 100644 --- a/src/mapleall/maple_ir/include/intrinsic_c.def +++ b/src/mapleall/maple_ir/include/intrinsic_c.def @@ -23,6 +23,8 @@ DEF_MIR_INTRINSIC(C_strcpy,\ "strcpy", 0, kArgTyVoid, kArgTyPtr, kArgTyPtr) DEF_MIR_INTRINSIC(C_strncpy,\ "strncpy", 0, kArgTyVoid, kArgTyPtr, kArgTyPtr, kArgTyU64) +DEF_MIR_INTRINSIC(C_strchr,\ + "strchr", 0, kArgTyVoid, kArgTyPtr, kArgTyI32) DEF_MIR_INTRINSIC(C_strlen,\ "strlen", INTRNNOSIDEEFFECT | INTRNISPURE, kArgTyU64, kArgTyPtr) DEF_MIR_INTRINSIC(C_memcmp,\ diff --git a/src/mplfe/ast_input/include/ast_builtin_func.def b/src/mplfe/ast_input/include/ast_builtin_func.def index 08747d4fbf5d36c34644539de5625b80938a342b..5cfac5db4e2dc51f8c96e607601ba0a7b2f42a9d 100644 --- a/src/mplfe/ast_input/include/ast_builtin_func.def +++ b/src/mplfe/ast_input/include/ast_builtin_func.def @@ -1,15 +1,6 @@ // BUILTIN_FUNC(funcName) BUILTIN_FUNC(printf) BUILTIN_FUNC(snprintf) -BUILTIN_FUNC(strncpy) -BUILTIN_FUNC(strcpy) -BUILTIN_FUNC(strcmp) -BUILTIN_FUNC(strlen) -BUILTIN_FUNC(strchr) -BUILTIN_FUNC(memcmp) -BUILTIN_FUNC(memcpy) -BUILTIN_FUNC(memset) -BUILTIN_FUNC(memmove) BUILTIN_FUNC(__memcpy_chk) BUILTIN_FUNC(__memset_chk) BUILTIN_FUNC(abs) diff --git a/src/mplfe/ast_input/include/ast_expr.h b/src/mplfe/ast_input/include/ast_expr.h index 4c913266f3e7955be5324655a609d162a608630d..2ec9d170588cb9011d79d9ea46d78ebf81020ce5 100644 --- a/src/mplfe/ast_input/include/ast_expr.h +++ b/src/mplfe/ast_input/include/ast_expr.h @@ -1213,6 +1213,17 @@ class ASTCallExpr : public ASTExpr { UniqueFEIRExpr EMIT_BUILTIIN_FUNC(SyncLockRelease4); UniqueFEIRExpr EMIT_BUILTIIN_FUNC(ReturnAddress); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Strcpy); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Strncpy); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Strchr); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Memcmp); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Memcpy); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Memset); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Strlen); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Strcmp); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Strncmp); + UniqueFEIRExpr EMIT_BUILTIIN_FUNC(Memmove); + // vector builtinfunc #define DEF_MIR_INTRINSIC(STR, NAME, INTRN_CLASS, RETURN_TYPE, ...) \ UniqueFEIRExpr EmitBuiltin##STR(std::list &stmts) const; diff --git a/src/mplfe/ast_input/include/builtin_func_emit.def b/src/mplfe/ast_input/include/builtin_func_emit.def index c51a39b6615d0aefcf5b6ababf58bb46e2629e1c..bd90b8219aa17efd0cc01a37c23f28035f58ede1 100644 --- a/src/mplfe/ast_input/include/builtin_func_emit.def +++ b/src/mplfe/ast_input/include/builtin_func_emit.def @@ -128,3 +128,24 @@ BUILTIN_FUNC_EMIT("__sync_lock_test_and_set_4", &ASTCallExpr::EmitBuiltinSyncLoc BUILTIN_FUNC_EMIT("__sync_lock_release_8", &ASTCallExpr::EmitBuiltinSyncLockRelease8) BUILTIN_FUNC_EMIT("__sync_lock_release_4", &ASTCallExpr::EmitBuiltinSyncLockRelease4) BUILTIN_FUNC_EMIT("__builtin_return_address", &ASTCallExpr::EmitBuiltinReturnAddress) + +BUILTIN_FUNC_EMIT("__builtin_strcpy", &ASTCallExpr::EmitBuiltinStrcpy) +BUILTIN_FUNC_EMIT("strcpy", &ASTCallExpr::EmitBuiltinStrcpy) +BUILTIN_FUNC_EMIT("__builtin_strncpy", &ASTCallExpr::EmitBuiltinStrncpy) +BUILTIN_FUNC_EMIT("strncpy", &ASTCallExpr::EmitBuiltinStrncpy) +BUILTIN_FUNC_EMIT("__builtin_strchr", &ASTCallExpr::EmitBuiltinStrchr) +BUILTIN_FUNC_EMIT("strchr", &ASTCallExpr::EmitBuiltinStrchr) +BUILTIN_FUNC_EMIT("__builtin_memcmp", &ASTCallExpr::EmitBuiltinMemcmp) +BUILTIN_FUNC_EMIT("memcmp", &ASTCallExpr::EmitBuiltinMemcmp) +BUILTIN_FUNC_EMIT("__builtin_memcpy", &ASTCallExpr::EmitBuiltinMemcpy) +BUILTIN_FUNC_EMIT("memcpy", &ASTCallExpr::EmitBuiltinMemcpy) +BUILTIN_FUNC_EMIT("__builtin_memset", &ASTCallExpr::EmitBuiltinMemset) +BUILTIN_FUNC_EMIT("memset", &ASTCallExpr::EmitBuiltinMemset) +BUILTIN_FUNC_EMIT("__builtin_strlen", &ASTCallExpr::EmitBuiltinStrlen) +BUILTIN_FUNC_EMIT("strlen", &ASTCallExpr::EmitBuiltinStrlen) +BUILTIN_FUNC_EMIT("__builtin_strcmp", &ASTCallExpr::EmitBuiltinStrcmp) +BUILTIN_FUNC_EMIT("strcmp", &ASTCallExpr::EmitBuiltinStrcmp) +BUILTIN_FUNC_EMIT("__builtin_strncmp", &ASTCallExpr::EmitBuiltinStrncmp) +BUILTIN_FUNC_EMIT("strncmp", &ASTCallExpr::EmitBuiltinStrncmp) +BUILTIN_FUNC_EMIT("__builtin_memmove", &ASTCallExpr::EmitBuiltinMemmove) +BUILTIN_FUNC_EMIT("memmove", &ASTCallExpr::EmitBuiltinMemmove) \ No newline at end of file diff --git a/src/mplfe/ast_input/src/ast_parser_builting_func.cpp b/src/mplfe/ast_input/src/ast_parser_builting_func.cpp index 71310111673ad59a59eab5481e546cd66d84cfd4..5f31e2aa73fbb2944fdcbbfe779fee3bcccefd7a 100644 --- a/src/mplfe/ast_input/src/ast_parser_builting_func.cpp +++ b/src/mplfe/ast_input/src/ast_parser_builting_func.cpp @@ -613,6 +613,45 @@ UniqueFEIRExpr ASTCallExpr::EmitBuiltinRotate(std::list &stmts, maskExpr->Clone()))); } +UniqueFEIRExpr ASTCallExpr::EmitBuiltinStrcpy(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_strcpy); +} +UniqueFEIRExpr ASTCallExpr::EmitBuiltinStrncpy(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_strncpy); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinMemcpy(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_memcpy); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinMemset(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_memset); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinMemcmp(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_memcmp); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinStrchr(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_strchr); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinStrlen(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_strlen); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinStrcmp(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_strcmp); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinStrncmp(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_strncmp); +} + +UniqueFEIRExpr ASTCallExpr::EmitBuiltinMemmove(std::list &stmts) const { + return CreateIntrinsicopForC(stmts, INTRN_C_memmove); +} + std::map ASTParser::InitBuiltinFuncPtrMap() { std::map ans; #define BUILTIN_FUNC_PARSE(funcName, FuncPtrBuiltinFunc) \