From db3fe50fe84ce4f38d88245a7ec70825d32990f5 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Tue, 29 Oct 2024 19:10:29 +0300 Subject: [PATCH 01/36] README.md adjustment --- static_core/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/static_core/README.md b/static_core/README.md index 9ec244042..26247e675 100644 --- a/static_core/README.md +++ b/static_core/README.md @@ -1,3 +1,9 @@ +# Experimental LLVM-Ark integration repository + +Panda version with experimental LLVM AOT / LLVM IRTOC changes. + +# Original Ark Runtime README + # Bootstrapping Currently an officially supported host OS for development, building and testing is Ubuntu 18.04 and Ubuntu 20.04. -- Gitee From fd62a1329d3e863a5761134f46b27e3bbcd5685f Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Wed, 16 Oct 2024 10:11:12 +0300 Subject: [PATCH 02/36] Adjust LLVM build script and readme --- static_core/scripts/llvm/README.md | 17 ++++++------ static_core/scripts/llvm/build_llvm.sh | 37 +++++++++++--------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/static_core/scripts/llvm/README.md b/static_core/scripts/llvm/README.md index 0faea9145..64d134804 100644 --- a/static_core/scripts/llvm/README.md +++ b/static_core/scripts/llvm/README.md @@ -15,6 +15,7 @@ Some variables are mandatory, others are optional. ```bash ### Required variables BUILD_DIR= +INSTALL_DIR= (default: "/opt", installing there usually requires root privileges) LLVM_SOURCES=/llvm VERSION=(default: "main") PACKAGE_VERSION=(default: $VERSION) # must match REQUIRED_LLVM_VERSION in libllvmbackend/CMakeLists.txt @@ -28,10 +29,9 @@ BUILD_OHOS_RELEASE=(default: BUILD_OHOS_RELEASE_GN=(default: false) ### Optional variables -INSTALL_DIR= (default: "") -DO_STRIPPING=(default: true) -DO_TAR=(default: true) +DO_STRIPPING=(default: true) +DO_TAR=(default: true) OHOS_SDK=, required for any OHOS build. @@ -59,21 +59,22 @@ LLVM_SOURCES="/home/user/src/llvm-for-ark/llvm" \ VERSION="15.0.4-ark99-beta9" \ PACKAGE_VERSION="15.0.4-ark99" \ OPTIMIZE_DEBUG=false \ +DO_STRIPPING=false \ BUILD_X86_DEBUG=true \ BUILD_AARCH64_DEBUG=true \ bash -x ./build_llvm.sh ``` In this example, only `x86_64` and `arm64` debug versions are built. Then, they can be specified for Ark build, like: -* host build: `-DLLVM_TARGET_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-x86_64` +* host build: `-DLLVM_TARGET_PATH=/home/user/inst/llvm-15.0.4-ark99-beta9-debug-x86_64` * cross-arm64 build: - * `-DLLVM_TARGET_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-aarch64` - * `-DLLVM_HOST_PATH=/home/user/build/llvm-15.0.4-ark99-beta9-debug-x86_64` + * `-DLLVM_TARGET_PATH=/home/user/inst/llvm-15.0.4-ark99-beta9-debug-aarch64` + * `-DLLVM_HOST_PATH=/home/user/inst/llvm-15.0.4-ark99-beta9-debug-x86_64` ## Example with packaging all necessary versions ```bash -INSTALL_DIR="/mnt/scratch/install" \ +INSTALL_DIR="/opt" \ BUILD_DIR="/mnt/scratch/build" \ LLVM_SOURCES="/mnt/scratch/src/llvm-for-ark/llvm" \ VERSION="15.0.4-ark99-beta9" \ @@ -86,5 +87,5 @@ BUILD_AARCH64_DEBUG=true \ BUILD_AARCH64_RELEASE=true \ BUILD_OHOS_RELEASE=true \ BUILD_OHOS_RELEASE_GN=true \ -bash -x ./build_llvm.sh +sudo bash -x ./build_llvm.sh ``` diff --git a/static_core/scripts/llvm/build_llvm.sh b/static_core/scripts/llvm/build_llvm.sh index df835fe12..f34c4055f 100755 --- a/static_core/scripts/llvm/build_llvm.sh +++ b/static_core/scripts/llvm/build_llvm.sh @@ -16,15 +16,17 @@ set -euo pipefail # Required variables BUILD_DIR=${BUILD_DIR:-""} +INSTALL_DIR=${INSTALL_DIR:-"/opt"} LLVM_SOURCES=${LLVM_SOURCES:-""} + # Optional variables -INSTALL_DIR=${INSTALL_DIR:-""} # empty -- do not install VERSION=${VERSION:-"main"} # Specifies build and install directory names: PACKAGE_VERSION=${PACKAGE_VERSION:-${VERSION}} BUILD_SUFFIX=${BUILD_SUFFIX:-""} # llvm--{debug,release}-{aarch64,x86} OPTIMIZE_DEBUG=${OPTIMIZE_DEBUG:-true} # Compile debug versions with -O2 -DO_STRIPPING=${DO_STRIPPING:-true} # checked only if install -DO_TARS=${DO_TARS:-true} # checked only if install +DO_STRIPPING=${DO_STRIPPING:-true} +DO_TARS=${DO_TARS:-true} + # Select a target to build BUILD_X86_DEBUG=${BUILD_X86_DEBUG:-false} BUILD_X86_RELEASE=${BUILD_X86_RELEASE:-false} @@ -52,6 +54,11 @@ if [[ -z "${BUILD_DIR}" ]]; then exit 1 fi +if [[ -z "${INSTALL_DIR}" ]]; then + echo "Please, specify install directory with INSTALL_DIR variable" + exit 1 +fi + if [[ -z "${LLVM_SOURCES}" ]]; then echo "Please, specify llvm sources directory with LLVM_SOURCES variable" exit 1 @@ -152,9 +159,7 @@ if [[ "x${BUILD_X86_DEBUG}" == "xtrue" ]]; then "${LLVM_SOURCES}" ninja distribution - if [[ -n "${INSTALL_DIR}" ]]; then - install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" - fi + install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" AUTO_LLVM_TABLEGEN="${BUILD_PREFIX}/bin/llvm-tblgen" if [[ ! -f "${AUTO_LLVM_TABLEGEN}" ]]; then @@ -195,9 +200,7 @@ if [[ "x${BUILD_X86_RELEASE}" == "xtrue" ]]; then "${LLVM_SOURCES}" ninja distribution - if [[ -n "${INSTALL_DIR}" ]]; then - install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" - fi + install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" AUTO_LLVM_TABLEGEN="${BUILD_PREFIX}/bin/llvm-tblgen" if [[ ! -f "${AUTO_LLVM_TABLEGEN}" ]]; then @@ -248,9 +251,7 @@ if [[ "x${BUILD_AARCH64_DEBUG}" == "xtrue" ]]; then "${LLVM_SOURCES}" ninja distribution - if [[ -n "${INSTALL_DIR}" ]]; then - install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" - fi + install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" fi if [[ "x${BUILD_AARCH64_RELEASE}" == "xtrue" ]]; then @@ -293,9 +294,7 @@ if [[ "x${BUILD_AARCH64_RELEASE}" == "xtrue" ]]; then "${LLVM_SOURCES}" ninja distribution - if [[ -n "${INSTALL_DIR}" ]]; then - install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" - fi + install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" fi if [[ "x${BUILD_OHOS_RELEASE}" == "xtrue" ]]; then @@ -332,9 +331,7 @@ if [[ "x${BUILD_OHOS_RELEASE}" == "xtrue" ]]; then "${LLVM_SOURCES}" ninja distribution - if [[ -n "${INSTALL_DIR}" ]]; then - install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" - fi + install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" fi if [[ "x${BUILD_OHOS_RELEASE_GN}" == "xtrue" ]]; then @@ -380,7 +377,5 @@ if [[ "x${BUILD_OHOS_RELEASE_GN}" == "xtrue" ]]; then "${LLVM_SOURCES}" ninja distribution - if [[ -n "${INSTALL_DIR}" ]]; then - install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" - fi + install "${INSTALL_PREFIX}" "${DO_STRIPPING}" "${DO_TARS}" fi -- Gitee From 4491d04e7615daa7fb0f666ecfe3032b248ed81a Mon Sep 17 00:00:00 2001 From: Leonid Skvortsov Date: Fri, 4 Oct 2024 18:22:56 +0300 Subject: [PATCH 03/36] Fix entrypoints in GN build --- static_core/libllvmbackend/BUILD.gn | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/static_core/libllvmbackend/BUILD.gn b/static_core/libllvmbackend/BUILD.gn index 59356034f..395a68e96 100644 --- a/static_core/libllvmbackend/BUILD.gn +++ b/static_core/libllvmbackend/BUILD.gn @@ -195,12 +195,13 @@ if (is_llvmbackend) { extra_dependencies = [ "$ark_root/runtime:arkruntime_gen_intrinsics_yaml" ] } - entrypoints_yaml = "$ark_root/runtime/entrypoints/entrypoints.yaml" + entrypoints_yaml = rebase_path("$target_gen_dir/../runtime/entrypoints.yaml") ark_gen_file("libllvmbackend_entrypoints_gen_inl") { template_file = "$llvmbackend_templates_dir/entrypoints_gen.inl.erb" data = [ entrypoints_yaml ] api = [ "$llvmbackend_templates_dir/entrypoints.rb" ] output_file = "$target_gen_dir/entrypoints_gen.inl" + extra_dependencies = [ "$ark_root:concat_entrypoints_yamls" ] } ark_gen_file("libllvmbackend_entrypoints_llvm_ark_interface_gen_inl") { @@ -209,6 +210,7 @@ if (is_llvmbackend) { data = [ entrypoints_yaml ] api = [ "$llvmbackend_templates_dir/entrypoints.rb" ] output_file = "$target_gen_dir/entrypoints_llvm_ark_interface_gen.inl" + extra_dependencies = [ "$ark_root:concat_entrypoints_yamls" ] } ark_gen_file("libllvmbackend_llvm_passes_inl") { -- Gitee From 3f4c60d99a1045ac354baa970032fa2f14f23440 Mon Sep 17 00:00:00 2001 From: Leonid Skvortsov Date: Tue, 8 Oct 2024 18:09:30 +0300 Subject: [PATCH 04/36] Follow NonNull attribute to intrinsic calls --- static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index de9caf53c..3c62b3351 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -4718,12 +4718,18 @@ void LLVMIrConstructor::VisitIntrinsic(GraphVisitor *v, Inst *inst) if (g_options.IsCompilerEncodeIntrinsics()) { bool lowered = ctor->TryEmitIntrinsic(inst, entryId); if (lowered) { + ASSERT(!inst->NoNullPtr()); return; } } // Create call otherwise auto result = ctor->CreateIntrinsicCall(inst); if (inst->GetType() != DataType::VOID) { + if (inst->NoNullPtr()) { + ASSERT(inst->GetType() == DataType::REFERENCE); + ASSERT(result->getType()->isPointerTy()); + result->addRetAttr(llvm::Attribute::NonNull); + } ctor->ValueMapAdd(inst, result); } } -- Gitee From 77af5c4255376b4bd2c87912219b0c32fe0d82bd Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Fri, 18 Oct 2024 10:17:32 +0300 Subject: [PATCH 05/36] Refactor 'EmitStringGetBytesTlab' Signed-off-by: Denis Zavedeev --- .../ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl b/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl index dd1ccbd70..9303f73a5 100644 --- a/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl +++ b/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl @@ -358,10 +358,8 @@ bool LLVMIrConstructor::EmitStringGetBytesTlab(Inst *inst) auto offset = GetGraph()->GetRuntime()->GetArrayU8ClassPointerTlsOffset(GetGraph()->GetArch()); auto klass = llvmbackend::runtime_calls::LoadTLSValue(&builder_, arkInterface_, offset, builder_.getPtrTy()); auto eid = RuntimeInterface::EntrypointId::STRING_GET_BYTES_TLAB; - auto result = CreateEntrypointCall(eid, inst, - {GetInputValue(inst, 0), GetInputValue(inst, 1), GetInputValue(inst, 2), klass}); - ASSERT(result->getCallingConv() == llvm::CallingConv::C); - result->setCallingConv(llvm::CallingConv::ArkFast4); + auto result = + CreateFastPathCall(inst, eid, {GetInputValue(inst, 0), GetInputValue(inst, 1), GetInputValue(inst, 2), klass}); result->addRetAttr(llvm::Attribute::NonNull); result->addRetAttr(llvm::Attribute::NoAlias); ValueMapAdd(inst, result); -- Gitee From 7aa301f8bdf50b8825d4ead96f274162dacb93ac Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Fri, 18 Oct 2024 10:41:33 +0300 Subject: [PATCH 06/36] Drop numArgs parameter in EmitFastPath Signed-off-by: Denis Zavedeev --- .../lowering/llvm_ir_constructor.cpp | 26 ++++++++++--------- .../lowering/llvm_ir_constructor.h | 2 +- .../ets_llvm_ir_constructor_gen.inl | 12 ++++----- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index 3c62b3351..02ca01495 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -678,11 +678,13 @@ bool LLVMIrConstructor::TryEmitIntrinsic(Inst *inst, RuntimeInterface::Intrinsic // Specific intrinsic Emitters -bool LLVMIrConstructor::EmitFastPath(Inst *inst, RuntimeInterface::EntrypointId eid, uint32_t numArgs) +bool LLVMIrConstructor::EmitFastPath(Inst *inst, RuntimeInterface::EntrypointId eid) { - ArenaVector args(GetGraph()->GetLocalAllocator()->Adapter()); - for (uint32_t i = 0; i < numArgs; i++) { - args.push_back(GetInputValue(inst, i)); + llvm::SmallVector args; + for (uint32_t i = 0; i < inst->GetInputsCount(); i++) { + if (!inst->GetInput(i).GetInst()->IsSaveState()) { + args.push_back(GetInputValue(inst, i)); + } } auto call = CreateFastPathCall(inst, eid, args); @@ -695,42 +697,42 @@ bool LLVMIrConstructor::EmitFastPath(Inst *inst, RuntimeInterface::EntrypointId bool LLVMIrConstructor::EmitStringEquals(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_EQUALS_COMPRESSED, 2U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_EQUALS_COMPRESSED); } bool LLVMIrConstructor::EmitStringBuilderBool(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_BUILDER_BOOL, 2U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_BUILDER_BOOL); } bool LLVMIrConstructor::EmitStringBuilderChar(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_BUILDER_CHAR, 2U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_BUILDER_CHAR); } bool LLVMIrConstructor::EmitStringBuilderString(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_BUILDER_STRING_COMPRESSED, 2U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_BUILDER_STRING_COMPRESSED); } bool LLVMIrConstructor::EmitStringConcat2(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_CONCAT2_TLAB, 2U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_CONCAT2_TLAB); } bool LLVMIrConstructor::EmitStringConcat3(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_CONCAT3_TLAB, 3U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_CONCAT3_TLAB); } bool LLVMIrConstructor::EmitStringConcat4(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_CONCAT4_TLAB, 4U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_CONCAT4_TLAB); } bool LLVMIrConstructor::EmitStringCompareTo(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_COMPARE_TO, 2U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_COMPARE_TO); } bool LLVMIrConstructor::EmitIsInf(Inst *inst) diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.h b/static_core/libllvmbackend/lowering/llvm_ir_constructor.h index 557db133e..8f53f5454 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.h +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.h @@ -34,7 +34,7 @@ class LLVMIrConstructor : public GraphVisitor { private: // Specific intrinsic Emitters - bool EmitFastPath(Inst *inst, RuntimeInterface::EntrypointId eid, uint32_t numArgs); + bool EmitFastPath(Inst *inst, RuntimeInterface::EntrypointId eid); bool EmitStringEquals(Inst *inst); bool EmitStringBuilderBool(Inst *inst); bool EmitStringBuilderChar(Inst *inst); diff --git a/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl b/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl index 9303f73a5..79305121e 100644 --- a/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl +++ b/static_core/plugins/ets/libllvmbackend/ets_llvm_ir_constructor_gen.inl @@ -48,7 +48,7 @@ bool LLVMIrConstructor::EmitArrayCopyTo(Inst *inst) bool LLVMIrConstructor::EmitStdStringSubstring(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::SUB_STRING_FROM_STRING_TLAB_COMPRESSED, 3U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::SUB_STRING_FROM_STRING_TLAB_COMPRESSED); } bool LLVMIrConstructor::EmitStringBuilderAppendBool(Inst *inst) @@ -160,7 +160,7 @@ bool LLVMIrConstructor::EmitStringBuilderAppendStrings(Inst *inst) default: UNREACHABLE(); } - return EmitFastPath(inst, eid, inst->GetInputsCount() - 1U); // -1 to skip save state + return EmitFastPath(inst, eid); } bool LLVMIrConstructor::EmitStringBuilderToString(Inst *inst) @@ -311,7 +311,7 @@ void LLVMIrConstructor::StringBuilderAppendStringMain(Inst *inst, llvm::Value *s bool LLVMIrConstructor::EmitDoubleToStringDecimal(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::DOUBLE_TO_STRING_DECIMAL, 3U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::DOUBLE_TO_STRING_DECIMAL); } bool LLVMIrConstructor::EmitStringTrimLeft(Inst *inst) @@ -340,17 +340,17 @@ bool LLVMIrConstructor::EmitStringTrim(Inst *inst) bool LLVMIrConstructor::EmitCharIsWhiteSpace(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::CHAR_IS_WHITE_SPACE, 1U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::CHAR_IS_WHITE_SPACE); } bool LLVMIrConstructor::EmitStringStartsWith(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_STARTS_WITH, 3U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_STARTS_WITH); } bool LLVMIrConstructor::EmitStringEndsWith(Inst *inst) { - return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_ENDS_WITH, 3U); + return EmitFastPath(inst, RuntimeInterface::EntrypointId::STRING_ENDS_WITH); } bool LLVMIrConstructor::EmitStringGetBytesTlab(Inst *inst) -- Gitee From 5892036f52e4193b4d786bec7a7f3ded1ffa7d34 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Wed, 16 Oct 2024 09:46:15 +0300 Subject: [PATCH 07/36] Bump llvm version to ark19 --- static_core/libllvmbackend/CMakeLists.txt | 2 +- static_core/libllvmbackend/llvm.gni | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/static_core/libllvmbackend/CMakeLists.txt b/static_core/libllvmbackend/CMakeLists.txt index d5f009d58..30c6db24d 100644 --- a/static_core/libllvmbackend/CMakeLists.txt +++ b/static_core/libllvmbackend/CMakeLists.txt @@ -228,7 +228,7 @@ endif() panda_target_compile_options(llvmbackend PUBLIC "-Wno-unused-parameter") -panda_target_compile_definitions(llvmbackend PUBLIC REQUIRED_LLVM_VERSION=15.0.4-ark18) +panda_target_compile_definitions(llvmbackend PUBLIC REQUIRED_LLVM_VERSION=15.0.4-ark19) if (PANDA_LLVM_AOT AND PANDA_TARGET_AMD64 AND PANDA_COMPILER_TARGET_AARCH64 AND PANDA_WITH_TESTS) set(PANDA_LLVM_AOT_TESTS_SOURCES diff --git a/static_core/libllvmbackend/llvm.gni b/static_core/libllvmbackend/llvm.gni index 227919178..b47bf0dbd 100644 --- a/static_core/libllvmbackend/llvm.gni +++ b/static_core/libllvmbackend/llvm.gni @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -llvm_version = "15.0.4-ark18" +llvm_version = "15.0.4-ark19" llvm_lib_file_suffix = "lib/libLLVM-15.so" declare_args() { -- Gitee From d5911b4ca3d95084d4416defd720784ce94c9c47 Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Fri, 18 Oct 2024 16:21:34 +0300 Subject: [PATCH 08/36] Use Tck_MustTail Signed-off-by: Denis Zavedeev --- static_core/libllvmbackend/llvm_irtoc_compiler.cpp | 1 + static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp | 5 +++-- static_core/tests/checked/checker.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/static_core/libllvmbackend/llvm_irtoc_compiler.cpp b/static_core/libllvmbackend/llvm_irtoc_compiler.cpp index 7d5e20f75..46b13c37e 100644 --- a/static_core/libllvmbackend/llvm_irtoc_compiler.cpp +++ b/static_core/libllvmbackend/llvm_irtoc_compiler.cpp @@ -165,6 +165,7 @@ void LLVMIrtocCompiler::InitializeSpecificLLVMOptions(Arch arch) SetLLVMOption("aarch64-enable-ptr32", "true"); } SetLLVMOption("inline-remark-attribute", "true"); + SetLLVMOption("verify-musttail-calls", "false"); LLVMCompiler::InitializeLLVMOptions(); } diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index 02ca01495..c384c7a11 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -828,7 +828,7 @@ bool LLVMIrConstructor::EmitSlowPathEntry(Inst *inst) auto call = builder_.CreateCall(callee->getFunctionType(), callee, args); call->setCallingConv(callee->getCallingConv()); - call->setTailCallKind(llvm::CallInst::TailCallKind::TCK_Tail); + call->setTailCallKind(llvm::CallInst::TailCallKind::TCK_MustTail); call->addFnAttr(llvm::Attribute::get(call->getContext(), "ark-tail-call")); CreateReturn(call); return true; @@ -946,7 +946,7 @@ bool LLVMIrConstructor::EmitTailCall(Inst *inst) } else { UNREACHABLE(); } - call->setTailCallKind(llvm::CallInst::TailCallKind::TCK_Tail); + call->setTailCallKind(llvm::CallInst::TailCallKind::TCK_MustTail); call->addFnAttr(llvm::Attribute::get(call->getContext(), "ark-tail-call")); CreateReturn(call); std::fill(ccValues_.begin(), ccValues_.end(), nullptr); @@ -2561,6 +2561,7 @@ llvm::CallInst *LLVMIrConstructor::CreateTailCallFastPath(Inst *inst) auto ftype = llvm::FunctionType::get(GetType(inst->GetType()), argTypes, false); callee = llvm::Function::Create(ftype, llvm::Function::ExternalLinkage, externalName, func_->getParent()); cc = func_->getCallingConv(); + callee->setCallingConv(cc); } else { size_t size = func_->arg_size(); ASSERT(callee->arg_size() <= size); diff --git a/static_core/tests/checked/checker.rb b/static_core/tests/checked/checker.rb index 5aaec8ac3..7f061f2a0 100755 --- a/static_core/tests/checked/checker.rb +++ b/static_core/tests/checked/checker.rb @@ -189,7 +189,7 @@ class Checker # Current search scope @disasm_scope = nil - Dir.mkdir(@cwd) unless File.exists?(@cwd) + Dir.mkdir(@cwd) unless File.exist?(@cwd) clear_data end -- Gitee From 92342edf1e985844c490083d4d0a8dca5eafdb2d Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Thu, 24 Oct 2024 12:02:29 +0300 Subject: [PATCH 09/36] [VMB] Support LLVMAOT and selecting interpreter --- static_core/tests/vm-benchmarks/src/vmb/cli.py | 14 +++++++++++++- .../src/vmb/plugins/platforms/arkts_device.py | 6 ++++-- .../src/vmb/plugins/platforms/arkts_host.py | 6 ++++-- .../vm-benchmarks/src/vmb/plugins/tools/ark.py | 6 ++++++ .../vm-benchmarks/src/vmb/plugins/tools/paoc.py | 6 +++++- static_core/tests/vm-benchmarks/src/vmb/tool.py | 9 ++++++++- 6 files changed, 40 insertions(+), 7 deletions(-) diff --git a/static_core/tests/vm-benchmarks/src/vmb/cli.py b/static_core/tests/vm-benchmarks/src/vmb/cli.py index 1aa21f7cb..010470e7c 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/cli.py +++ b/static_core/tests/vm-benchmarks/src/vmb/cli.py @@ -61,7 +61,11 @@ def add_measurement_opts(parser: argparse.ArgumentParser) -> None: help='If >= 0 invoke GC twice ' 'and wait ms before iteration') parser.add_argument("-aot-co", "--aot-compiler-options", default=[], - type=str, action="append", help="aot-compiler options") + type=str, action="append", + help="Sets ahead-of-time compiler options") + parser.add_argument("-aot-lib-co", "--aot-lib-compiler-options", default=[], + type=str, action="append", + help="Sets ahead-of-time compiler options for libraries") parser.add_argument("-c", "--concurrency-level", default=None, type=str, help="Concurrency level (DEPRECATED)") @@ -272,8 +276,16 @@ class Args(argparse.Namespace): mode = ToolMode(self.get('mode')) if ToolMode.AOT == mode: flags |= OptFlags.AOT + elif ToolMode.LLVMAOT == mode: + flags |= OptFlags.AOT | OptFlags.LLVMAOT elif ToolMode.INT == mode: flags |= OptFlags.INT + elif ToolMode.INT_CPP == mode: + flags |= OptFlags.INT | OptFlags.INT_CPP + elif ToolMode.INT_IRTOC == mode: + flags |= OptFlags.INT | OptFlags.INT_IRTOC + elif ToolMode.INT_LLVM == mode: + flags |= OptFlags.INT | OptFlags.INT_LLVM elif ToolMode.JIT == mode: flags |= OptFlags.JIT if self.get('dry_run', False): diff --git a/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_device.py b/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_device.py index 268f2d8a5..9e354d09d 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_device.py +++ b/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_device.py @@ -41,9 +41,11 @@ class Platform(PlatformBase): log.info('Skipping aot compilation of libs') else: an = Path(self.ark.etsstdlib).with_suffix('.an') - log.info('AOT-Compiling %s. This may took a long time...', + aot_lib_opts = ' '.join(args.aot_lib_compiler_options) + log.info('AOT-Compiling %s. This may take a long time...', self.ark.etsstdlib) - res = self.paoc.run_paoc(self.ark.etsstdlib, an, timeout=1800) + res = self.paoc.run_paoc(self.ark.etsstdlib, an, + opts=aot_lib_opts, timeout=1800) if not self.ext_info.get('etsstdlib', {}): self.ext_info['etsstdlib'] = {} self.ext_info['etsstdlib']['etsstdlib.an'] = \ diff --git a/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_host.py b/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_host.py index e6e9e419e..5b3120d5d 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_host.py +++ b/static_core/tests/vm-benchmarks/src/vmb/plugins/platforms/arkts_host.py @@ -43,9 +43,11 @@ class Platform(PlatformBase): else: an = ToolBase.libs.joinpath( Path(self.ark.etsstdlib).with_suffix('.an').name) - log.info('AOT-Compiling %s. This may took a long time...', + aot_lib_opts = ' '.join(args.aot_lib_compiler_options) + log.info('AOT-Compiling %s. This may take a long time...', self.ark.etsstdlib) - res = self.paoc.run_paoc(self.ark.etsstdlib, an, timeout=1800) + res = self.paoc.run_paoc(self.ark.etsstdlib, an, + opts=aot_lib_opts, timeout=1800) if not self.ext_info.get('etsstdlib', {}): self.ext_info['etsstdlib'] = {} self.ext_info['etsstdlib']['etsstdlib.an'] = \ diff --git a/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/ark.py b/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/ark.py index 3f4084b05..536e0bbf6 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/ark.py +++ b/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/ark.py @@ -50,6 +50,12 @@ class Tool(ToolBase): an_files.append(stdlib) if OptFlags.INT in self.flags: opts += '--compiler-enable-jit=false ' + if OptFlags.INT_CPP in self.flags: + opts += '--interpreter-type=cpp ' + if OptFlags.INT_IRTOC in self.flags: + opts += '--interpreter-type=irtoc ' + if OptFlags.INT_LLVM in self.flags: + opts += '--interpreter-type=llvm ' if OptFlags.GC_STATS in self.flags: opts += '--print-gc-statistics --log-components=gc ' \ '--log-level=info --log-stream=file ' \ diff --git a/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/paoc.py b/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/paoc.py index 43bc2b616..b8b87ec72 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/paoc.py +++ b/static_core/tests/vm-benchmarks/src/vmb/plugins/tools/paoc.py @@ -50,8 +50,12 @@ class Tool(ToolBase): aot_stats = '--compiler-dump-stats-csv={an}.dump.csv ' else: aot_stats = '' + if OptFlags.LLVMAOT in self.flags: + aot_mode = '--paoc-mode=llvm ' + else: + aot_mode = '--paoc-mode=aot ' self.cmd = f'LD_LIBRARY_PATH={self.ark_lib} {self.paoc} ' \ - f'--boot-panda-files={self.etsstdlib} ' \ + f'--boot-panda-files={self.etsstdlib} {aot_mode} ' \ '--load-runtimes=ets {opts} ' \ f'{self.custom} {aot_stats}' \ '--paoc-panda-files={abc} ' \ diff --git a/static_core/tests/vm-benchmarks/src/vmb/tool.py b/static_core/tests/vm-benchmarks/src/vmb/tool.py index dad6d25e8..e814add66 100644 --- a/static_core/tests/vm-benchmarks/src/vmb/tool.py +++ b/static_core/tests/vm-benchmarks/src/vmb/tool.py @@ -47,6 +47,10 @@ class ToolMode(StringEnum): AOT = 'aot' INT = 'int' JIT = 'jit' + INT_CPP = 'int-cpp' + INT_IRTOC = 'int-irtoc' + INT_LLVM = 'int-llvm' + LLVMAOT = 'llvmaot' DEFAULT = 'default' @@ -58,10 +62,13 @@ class OptFlags(Flag): AOT_SKIP_LIBS = auto() DRY_RUN = auto() DISABLE_INLINING = auto() - # these 3 flags are mutually exclusive (this is guarantied by ToolMode) AOT = auto() INT = auto() JIT = auto() + INT_CPP = auto() + INT_IRTOC = auto() + INT_LLVM = auto() + LLVMAOT = auto() class ToolBase(CrossShell, ABC): -- Gitee From 5f21f93c57b8cf807eadc034a2c93981fa70192d Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Fri, 27 Sep 2024 16:18:09 +0300 Subject: [PATCH 10/36] [CI] Clang-tidy/clang-format scripts adjustments --- static_core/CMakeLists.txt | 2 +- static_core/cmake/ClangTidy.cmake | 6 +++ .../clang-tidy/clang-tidy_llvm_config.json | 10 ++++ .../scripts/clang-tidy/clang_tidy_check.py | 54 ++++++++++++++----- .../scripts/code_style/code_style_check.py | 21 +++++--- 5 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 static_core/scripts/clang-tidy/clang-tidy_llvm_config.json diff --git a/static_core/CMakeLists.txt b/static_core/CMakeLists.txt index ddc400a3f..63d72c8c4 100644 --- a/static_core/CMakeLists.txt +++ b/static_core/CMakeLists.txt @@ -347,7 +347,7 @@ if(PANDA_WITH_TESTS) ) if (NOT PANDA_TARGET_MACOS) - add_dependencies(tests_full code-style-check) + add_dependencies(tests_full code-style-check doxygen-style-check clang-tidy-llvmbackend) endif() add_subdirectory(scripts) diff --git a/static_core/cmake/ClangTidy.cmake b/static_core/cmake/ClangTidy.cmake index 1d6bf74d8..444bf268b 100644 --- a/static_core/cmake/ClangTidy.cmake +++ b/static_core/cmake/ClangTidy.cmake @@ -40,3 +40,9 @@ add_custom_target(test-cmake-checker COMMAND ${PANDA_ROOT}/scripts/cmake-checker/cmake_checker.py ${PANDA_ROOT} TEST USES_TERMINAL ) + +add_custom_target(clang-tidy-llvmbackend + COMMAND ${PANDA_ROOT}/scripts/clang-tidy/clang_tidy_check.py ${PANDA_ROOT} ${PANDA_BINARY_ROOT} "--cfg-filter=${PANDA_ROOT}/scripts/clang-tidy/clang-tidy_llvm_config.json" + USES_TERMINAL + DEPENDS panda_gen_files +) diff --git a/static_core/scripts/clang-tidy/clang-tidy_llvm_config.json b/static_core/scripts/clang-tidy/clang-tidy_llvm_config.json new file mode 100644 index 000000000..ebf474cc2 --- /dev/null +++ b/static_core/scripts/clang-tidy/clang-tidy_llvm_config.json @@ -0,0 +1,10 @@ +[ + "libllvmbackend", + "irtoc/backend/", + "compiler/aot/aot_builder/aot_builder.cpp", + "compiler/aot/aot_builder/llvm_aot_builder.cpp", + "compiler/aot/aot_file.cpp", + "compiler/optimizer/ir/aot_data.cpp", + "compiler/tools/paoc/paoc.cpp", + "compiler/tools/paoc/paoc_llvm.cpp" +] diff --git a/static_core/scripts/clang-tidy/clang_tidy_check.py b/static_core/scripts/clang-tidy/clang_tidy_check.py index c6e5b3492..97a5d4753 100755 --- a/static_core/scripts/clang-tidy/clang_tidy_check.py +++ b/static_core/scripts/clang-tidy/clang_tidy_check.py @@ -29,9 +29,13 @@ def get_args(): 'panda_dir', help='panda sources directory.', type=str) parser.add_argument( 'build_dir', help='panda build directory.', type=str) + parser.add_argument( + '--cfg-filter', type=str, action='store', dest='cfg_filter', + required=False, + help='Path to config with filenames to be checked. If missed all source files will be checked.') parser.add_argument( '--filename-filter', type=str, action='store', dest='filename_filter', - required=False, default="*", + required=False, help='Regexp for filename with path to it. If missed all source files will be checked.') parser.add_argument( '--full', action="store_true", help='Check all files with all compile keys.') @@ -213,7 +217,7 @@ default_disabled_checks = [ ] -def run_clang_tidy(src_path: str, config_file_path: str, build_dir: str, header_filter: str, compile_args: str) -> bool: +def run_clang_tidy(src_path: str, config_file_path: str, build_dir: str, header_filter: str, compile_args: str, delayed_stderr: list, job_num: int) -> bool: # Used by ctcache to provide a wrapper for real clang-tidy that will check the cache # before launching clang-tidy and save the result to ctcache server cmd_path = os.getenv('CLANG_TIDY_PATH') @@ -240,10 +244,14 @@ def run_clang_tidy(src_path: str, config_file_path: str, build_dir: str, header_ print("Note: bad output for ", src_path) return True - print('Failed: ' + ' '.join(cmd) + '\n' + out_msg) + failed_output = f'Failed: ' + ' '.join(cmd) + failed_output += f'\n{out_msg}\n' if e.stderr: - print(e.stderr.decode()) + failed_output += e.stderr.decode() + + delayed_stderr[job_num] = failed_output + print(failed_output) return False @@ -260,12 +268,15 @@ def get_full_path(relative_path: str, location_base: str, panda_dir: str, build_ def check_file_list(file_list: list, panda_dir: str, build_dir: str, header_filter: str, proc_count: int) -> bool: pool = multiprocessing.Pool(proc_count) jobs = [] - for src, args in file_list: + manager = multiprocessing.Manager() + delayed_stderr = manager.list([None] * len(file_list)) + for i in range(len(file_list)): + src, args = file_list[i] msg = "Done clang-tidy: %s" % (src) proc = pool.apply_async(func=run_clang_tidy, args=( - src, panda_dir, build_dir, header_filter, args)) + src, panda_dir, build_dir, header_filter, args, delayed_stderr, i)) jobs.append((proc, msg)) # Wait for jobs to complete before exiting @@ -289,6 +300,7 @@ def check_file_list(file_list: list, panda_dir: str, build_dir: str, header_filt # Safely terminate the pool pool.close() pool.join() + print('\n'.join([ds for ds in delayed_stderr if ds])) return main_ret_val @@ -409,10 +421,13 @@ def verify_uniq_element_list(uniq_element_list: list) -> bool: return len(uniq_element_list) == len(set(uniq_element_list)) -def verify_args(panda_dir: str, build_dir: str) -> str: +def verify_args(panda_dir: str, build_dir: str, filename_filter: str, cfg_filter: str): if not verify_uniq_element_list(default_disabled_checks): return "Error: Dupclicated defauls disabled checks" + if filename_filter and cfg_filter: + return "Error: --filename-filter and --cfg-filter cannot be used together, please remove one." + return "" @@ -458,6 +473,13 @@ def get_proc_count(cmd_ard : int) -> int: return multiprocessing.cpu_count() +def parse_config(cfg_filter): + cfg_data = None + with open(cfg_filter) as cfg: + cfg_data = json.load(cfg) + return f"({'|'.join(cfg_data)})" + + if __name__ == "__main__": arguments = get_args() files_list = [] @@ -470,17 +492,25 @@ if __name__ == "__main__": default_disabled_checks.append("-fuchsia-statically-constructed-objects") default_disabled_checks.append("-cert-err58-cpp") - err_msg = verify_args(arguments.panda_dir, arguments.build_dir) + err_msg = verify_args( + arguments.panda_dir, arguments.build_dir, arguments.filename_filter, arguments.cfg_filter) if err_msg: sys.exit(err_msg) - files_list = get_file_list( - arguments.panda_dir, arguments.build_dir, arguments.filename_filter) + filename_filter = "*" + + if arguments.filename_filter: + filename_filter = arguments.filename_filter + elif arguments.cfg_filter: + filename_filter = parse_config(arguments.cfg_filter) + + files_list = get_file_list(arguments.panda_dir, arguments.build_dir, filename_filter) if not files_list: sys.exit("Can't be prepaired source list." - "Please check availble in build `dir compile_commands.json`" - "and correcting of parameter `--filename-filter` if you use it.") + "Please check available in build `dir compile_commands.json`" + "and correcting of parameter `--filename-filter`" + " or `--cfg-filter` if you use it.") if not arguments.check_libabckit: check_headers_in_es2panda_sources(arguments.panda_dir) diff --git a/static_core/scripts/code_style/code_style_check.py b/static_core/scripts/code_style/code_style_check.py index b3a8ad6c5..f8735d1e9 100755 --- a/static_core/scripts/code_style/code_style_check.py +++ b/static_core/scripts/code_style/code_style_check.py @@ -39,7 +39,7 @@ def get_args(): return parser.parse_args() -def run_clang_format(src_path, panda_dir, reformat, msg): +def run_clang_format(src_path, panda_dir, reformat, msg, delayed_stderr, job_num): check_cmd = [str(os.path.join(panda_dir, 'scripts', 'code_style', 'run_code_style_tools.sh'))] reformat_cmd = [CLANG_FORMAT, '-i'] @@ -56,11 +56,14 @@ def run_clang_format(src_path, panda_dir, reformat, msg): print("Note: missed output for ", src_path) return True - print('Failed: ', ' '.join(cmd)) - print(e.stdout.decode()) + failed_output = f'Failed: ' + ' '.join(cmd) + failed_output += f'\n{e.stdout.decode()}\n' if e.stderr: - print(e.stderr.decode()) + failed_output += e.stderr.decode() + + delayed_stderr[job_num] = failed_output + print(failed_output) return False @@ -84,16 +87,19 @@ def check_file_list(file_list : list, panda_dir : str, reformat : bool, proc_cou main_ret_val = True total_count = str(len(file_list)) idx = 0 - for src in file_list: + manager = multiprocessing.Manager() + delayed_stderr = manager.list([None] * len(file_list)) + for i in range(len(file_list)): + src = file_list[i] idx += 1 msg = "[%s/%s] Running clang-format: %s" % (str(idx), total_count, src) proc = pool.apply_async(func=run_clang_format, args=( - src, panda_dir, reformat, msg)) + src, panda_dir, reformat, msg, delayed_stderr, i)) jobs.append(proc) # Wait for jobs to complete before exiting while(not all([p.ready() for p in jobs])): - time.sleep(5) + time.sleep(1) for job in jobs: if not job.get(): @@ -103,6 +109,7 @@ def check_file_list(file_list : list, panda_dir : str, reformat : bool, proc_cou # Safely terminate the pool pool.close() pool.join() + print('\n'.join([ds for ds in delayed_stderr if ds])) return main_ret_val -- Gitee From 04ee6164a93a2587fd032f11dc9a8b43c583b541 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Thu, 26 Sep 2024 18:42:07 +0300 Subject: [PATCH 11/36] [CI] Tweak llvmaot options for etsstdlib --- static_core/plugins/ets/CMakeLists.txt | 13 +++- static_core/plugins/ets/tests/CMakeLists.txt | 73 ++++++-------------- 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/static_core/plugins/ets/CMakeLists.txt b/static_core/plugins/ets/CMakeLists.txt index aa939c5aa..40530c4a8 100644 --- a/static_core/plugins/ets/CMakeLists.txt +++ b/static_core/plugins/ets/CMakeLists.txt @@ -126,10 +126,19 @@ endif() if(PANDA_WITH_COMPILER) add_subdirectory(compiler) - set (COMPILER_OPTIONS "--compiler-check-final=true") + if(PANDA_LLVM_AOT) + set(STDLIB_PAOC_MODE "llvm") + set(COMPILER_OPTIONS "--compiler-check-final=true" "--llvm-gc-check=true" "--llvm-pre-opt=2") + if (NOT PANDA_ENABLE_THREAD_SANITIZER) + set(COMPILER_OPTIONS ${COMPILER_OPTIONS} "--llvmaot-threads=4" "--llvmaot-methods-per-module=512") + endif() + else() + set(STDLIB_PAOC_MODE "aot") + set(COMPILER_OPTIONS "--compiler-check-final=true") + endif() add_custom_target(ets-compile-stdlib-default COMMENT "Running ark_aot compilation for etsstdlib with default options" - COMMAND ${CMAKE_SOURCE_DIR}/plugins/ets/compiler/tools/paoc_compile_stdlib.sh --prefix="${PANDA_RUN_PREFIX}" --binary-dir=${CMAKE_BINARY_DIR} -compiler-options="${COMPILER_OPTIONS}" -paoc-output=${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.an + COMMAND ${CMAKE_SOURCE_DIR}/plugins/ets/compiler/tools/paoc_compile_stdlib.sh --prefix="${PANDA_RUN_PREFIX}" --binary-dir=${CMAKE_BINARY_DIR} -compiler-options="${COMPILER_OPTIONS}" --paoc-mode=${STDLIB_PAOC_MODE} -paoc-output=${CMAKE_CURRENT_BINARY_DIR}/etsstdlib.an DEPENDS ark_aot etsstdlib ) endif() diff --git a/static_core/plugins/ets/tests/CMakeLists.txt b/static_core/plugins/ets/tests/CMakeLists.txt index e5e1ddaa8..a738b060b 100644 --- a/static_core/plugins/ets/tests/CMakeLists.txt +++ b/static_core/plugins/ets/tests/CMakeLists.txt @@ -432,51 +432,32 @@ endfunction() set (COMPILER_OPTIONS_OSR "--compiler-ignore-failures=true" ${COMPILER_OPTIONS}) function(compile_stdlib TARGET_ARCH) - add_custom_target(ets-compile-stdlib-aot-${TARGET_ARCH} - COMMENT "Running ark_aot compilation for etsstdlib for ${TARGET_ARCH} with default options" - COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=aot -compiler-options="${COMPILER_OPTIONS}" -paoc-output=etsstdlib_aot_${TARGET_ARCH}.an - DEPENDS ark_aot etsstdlib - ) - add_custom_target(ets-compile-stdlib-jit-${TARGET_ARCH} - COMMENT "Running ark_aot compilation for etsstdlib for ${TARGET_ARCH} with jit mode" - COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=jit -compiler-options="${COMPILER_OPTIONS}" -paoc-output=etsstdlib_jit_${TARGET_ARCH}.an - DEPENDS ark_aot etsstdlib - ) - add_custom_target(ets-compile-stdlib-aot-${TARGET_ARCH}-no-inline - COMMENT "Running ark_aot compilation for etsstdlib for ${TARGET_ARCH} without inlining" - COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=aot -compiler-options="${COMPILER_OPTIONS_NO_INLINE}" -paoc-output=etsstdlib_aot_${TARGET_ARCH}_no_inline.an - DEPENDS ark_aot etsstdlib - ) - add_custom_target(ets-compile-stdlib-aot-${TARGET_ARCH}-stw - COMMENT "Running ark_aot compilation for etsstdlib for ${TARGET_ARCH} with gc stw" - COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=aot -compiler-options="${COMPILER_OPTIONS_GC_STW}" -paoc-output=etsstdlib_aot_${TARGET_ARCH}_stw.an - DEPENDS ark_aot etsstdlib - ) - add_dependencies(ets-compile-stdlib ets-compile-stdlib-aot-${TARGET_ARCH} ets-compile-stdlib-jit-${TARGET_ARCH} ets-compile-stdlib-aot-${TARGET_ARCH}-no-inline ets-compile-stdlib-aot-${TARGET_ARCH}-stw) if (PANDA_LLVM_AOT) - add_custom_target(ets-compile-stdlib-llvm-${TARGET_ARCH} - COMMENT "Running ark_aot compilation for etsstdlib for ${TARGET_ARCH} with llvm" - COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=llvm -compiler-options="${COMPILER_OPTIONS_LLVM}" -paoc-output=etsstdlib_llvmaot_${TARGET_ARCH}.an + add_custom_target(ets-compile-stdlib-llvmaot-${TARGET_ARCH} + COMMENT "Running LLVMAOT compilation for etsstdlib for ${TARGET_ARCH}" + COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=llvm -compiler-options="${COMPILER_OPTIONS}" -paoc-output=etsstdlib_llvmaot_${TARGET_ARCH}.an DEPENDS ark_aot etsstdlib ) - add_custom_target(ets-compile-stdlib-llvm-pre-opt-2-${TARGET_ARCH} - COMMENT "Running ark_aot compilation for etsstdlib for ${TARGET_ARCH} with llvm pre-opt" - COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=llvm -compiler-options="${COMPILER_OPTIONS_LLVM_PRE_OPT}" -paoc-output=etsstdlib_llvmaot_pre_opt_2_${TARGET_ARCH}.an + add_custom_target(ets-compile-stdlib-llvmaot-${TARGET_ARCH}-no-inline + COMMENT "Running LLVMAOT compilation for etsstdlib for ${TARGET_ARCH} without inlining" + COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=llvm -compiler-options="${COMPILER_OPTIONS_NO_INLINE}" -paoc-output=etsstdlib_llvmaot_${TARGET_ARCH}_no_inline.an DEPENDS ark_aot etsstdlib ) - add_dependencies( - ets-compile-stdlib - ets-compile-stdlib-llvm-${TARGET_ARCH} - ets-compile-stdlib-llvm-pre-opt-2-${TARGET_ARCH} + add_custom_target(ets-compile-stdlib-llvmaot-${TARGET_ARCH}-no-pre-opt + COMMENT "Running LLVMAOT compilation for etsstdlib for ${TARGET_ARCH} with llvm without pre-opt" + COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=llvm -compiler-options="${COMPILER_OPTIONS_NO_PRE_OPT}" -paoc-output=etsstdlib_llvmaot_${TARGET_ARCH}_no_pre_opt.an + DEPENDS ark_aot etsstdlib ) - endif() - if (TARGET_ARCH STREQUAL "arm64") - add_custom_target(ets-compile-stdlib-osr-${TARGET_ARCH} - COMMENT "Running ark_aot compilation for etsstdlib for ${TARGET_ARCH} with osr mode" - COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=osr -compiler-options="${COMPILER_OPTIONS_OSR}" -paoc-output=etsstdlib_osr_${TARGET_ARCH}.an + add_custom_target(ets-compile-stdlib-llvmaot-${TARGET_ARCH}-stw + COMMENT "Running LLVMAOT compilation for etsstdlib for ${TARGET_ARCH} with gc stw" + COMMAND ${ARK_AOT_RUNNER} --binary-dir=${CMAKE_BINARY_DIR} --target-arch=${TARGET_ARCH} --paoc-mode=llvm -compiler-options="${COMPILER_OPTIONS_GC_STW}" -paoc-output=etsstdlib_llvmaot_${TARGET_ARCH}_stw.an DEPENDS ark_aot etsstdlib ) - add_dependencies(ets-compile-stdlib ets-compile-stdlib-osr-${TARGET_ARCH}) + add_dependencies(ets-compile-stdlib + ets-compile-stdlib-llvmaot-${TARGET_ARCH} + ets-compile-stdlib-llvmaot-${TARGET_ARCH}-no-inline + ets-compile-stdlib-llvmaot-${TARGET_ARCH}-no-pre-opt + ets-compile-stdlib-llvmaot-${TARGET_ARCH}-stw) endif() endfunction() @@ -495,23 +476,13 @@ endif() if(PANDA_TEST_COMPILE_STDLIB) set (ARK_AOT_RUNNER ${CMAKE_SOURCE_DIR}/plugins/ets/compiler/tools/paoc_compile_stdlib.sh) - if (NOT PANDA_CI_TESTING_MODE STREQUAL "Nightly") - set (COMPILER_OPTIONS "--compiler-check-final=true") - if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - set (COMPILER_OPTIONS ${COMPILER_OPTIONS} "--compiler-inst-graph-coloring-limit=2000") - endif() + set (COMPILER_OPTIONS "--compiler-check-final=true" "--llvm-gc-check=true" "--llvm-pre-opt=2") + if (NOT PANDA_ENABLE_THREAD_SANITIZER) + set (COMPILER_OPTIONS ${COMPILER_OPTIONS} "--llvmaot-threads=4" "--llvmaot-methods-per-module=512") endif() set (COMPILER_OPTIONS_NO_INLINE "--compiler-inlining=false" ${COMPILER_OPTIONS}) set (COMPILER_OPTIONS_GC_STW "--gc-type=stw" ${COMPILER_OPTIONS}) - if (PANDA_LLVM_AOT) - set (COMPILER_OPTIONS_LLVM ${COMPILER_OPTIONS}) - set (COMPILER_OPTIONS_LLVM_PRE_OPT "--llvm-pre-opt=2" ${COMPILER_OPTIONS}) - # NOTE(zdenis): False positives come from libLLVM.so - if (NOT PANDA_ENABLE_THREAD_SANITIZER) - set (COMPILER_OPTIONS_LLVM "--llvmaot-threads=4" "--llvmaot-methods-per-module=512" ${COMPILER_OPTIONS_LLVM}) - set (COMPILER_OPTIONS_LLVM_PRE_OPT "--llvmaot-threads=4" "--llvmaot-methods-per-module=512" ${COMPILER_OPTIONS_LLVM_PRE_OPT}) - endif() - endif () + set (COMPILER_OPTIONS_NO_PRE_OPT ${COMPILER_OPTIONS} "--llvm-pre-opt=0") add_custom_target(ets-compile-stdlib) if (PANDA_COMPILER_TARGET_X86_64) compile_stdlib(x86_64) -- Gitee From 43fd84a4aace01c4166d3581dc2f7bd0d736c94c Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Thu, 26 Sep 2024 18:43:07 +0300 Subject: [PATCH 12/36] [CI] Enable libllvmbackend in "Panda SDK" builds --- static_core/scripts/sdk/build_sdk_lib | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/static_core/scripts/sdk/build_sdk_lib b/static_core/scripts/sdk/build_sdk_lib index f4721c5a2..6f4f7b6cf 100644 --- a/static_core/scripts/sdk/build_sdk_lib +++ b/static_core/scripts/sdk/build_sdk_lib @@ -26,7 +26,7 @@ function build_panda() { COMMONS_CMAKE_ARGS="\ -GNinja \ -S$ARK_ROOT \ - -DCMAKE_BUILD_TYPE=$PANDA_SDK_BUILD_TYPE \ + -DCMAKE_BUILD_TYPE=${PANDA_SDK_BUILD_TYPE} \ -DPANDA_PRODUCT_BUILD=$product_build \ -DPANDA_WITH_ECMASCRIPT=ON \ -DPANDA_WITH_ETS=ON \ @@ -79,7 +79,10 @@ function linux_tools() { -DPANDA_CROSS_AARCH64_TOOLCHAIN_FILE=cmake/toolchain/cross-ohos-musl-aarch64.cmake \ -DTOOLCHAIN_SYSROOT=$OHOS_SDK_NATIVE/sysroot \ -DTOOLCHAIN_CLANG_ROOT=$OHOS_SDK_NATIVE/llvm \ - -DPANDA_WITH_ECMASCRIPT=ON" + -DPANDA_WITH_ECMASCRIPT=ON \ + -DPANDA_LLVM_BACKEND=ON \ + -DLLVM_TARGET_PATH=/opt/llvm-15-${PANDA_SDK_BUILD_TYPE,,}-x86_64" + local linux_build_targets="ark ark_aot ark_disasm ark_link es2panda e2p_test_plugin etsnative" build_panda "$linux_build_dir" "$linux_cmake_args" "$linux_build_targets" copy_into_sdk "$linux_build_dir" "$PANDA_SDK_PATH/linux_host_tools" "$SCRIPT_DIR"/linux_host_tools.txt @@ -103,7 +106,11 @@ function ohos() { -DTOOLCHAIN_SYSROOT=$OHOS_SDK_NATIVE/sysroot \ -DTOOLCHAIN_CLANG_ROOT=$OHOS_SDK_NATIVE/llvm \ -DPANDA_ETS_INTEROP_JS=ON \ - -DPANDA_WITH_ECMASCRIPT=ON" + -DPANDA_WITH_ECMASCRIPT=ON \ + -DPANDA_LLVM_BACKEND=ON \ + -DLLVM_HOST_PATH=/opt/llvm-15-${PANDA_SDK_BUILD_TYPE,,}-x86_64 \ + -DLLVM_TARGET_PATH=/opt/llvm-15-release-ohos" + local ohos_build_targets="ark ark_aot arkruntime arkassembler ets_interop_js_napi e2p_test_plugin etsnative" build_panda "$ohos_build_dir" "$target_cmake_args" "$ohos_build_targets" copy_into_sdk "$ohos_build_dir" "$taget_sdk_dir" "$SCRIPT_DIR"/ohos_arm64.txt -- Gitee From 47fcdf17ac742366a64098189990f7eee69c5a99 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Fri, 27 Sep 2024 13:53:48 +0300 Subject: [PATCH 13/36] [CI] cts-generator: add arm64-host and llvm-irtoc runs --- static_core/tests/CMakeLists.txt | 3 ++ .../tests/cts-generator/CMakeLists.txt | 29 +------------------ 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/static_core/tests/CMakeLists.txt b/static_core/tests/CMakeLists.txt index aa236767b..697a203d1 100644 --- a/static_core/tests/CMakeLists.txt +++ b/static_core/tests/CMakeLists.txt @@ -31,6 +31,9 @@ add_dependencies(irtoc-interpreter-tests irtoc-opcode-suite) if(NOT PANDA_TARGET_AMD64 OR PANDA_TARGET_WINDOWS) add_dependencies(core_tests cts-assembly regression) add_subdirectory(cts-coverage-tool) + if(PANDA_TARGET_ARM64 AND NOT CMAKE_CROSSCOMPILING) + add_subdirectory(cts-generator) + endif() else() add_custom_target(verifier-tests COMMENT "Regression tests for verifier") add_dependencies(core_tests cts-assembly regression verifier-tests) diff --git a/static_core/tests/cts-generator/CMakeLists.txt b/static_core/tests/cts-generator/CMakeLists.txt index 92b74363c..aba30003c 100644 --- a/static_core/tests/cts-generator/CMakeLists.txt +++ b/static_core/tests/cts-generator/CMakeLists.txt @@ -157,19 +157,7 @@ if(NOT CMAKE_CROSSCOMPILING) -p "${PROJECT_BINARY_DIR}/../../" -x "${CTS_TEMP_DIR}" -v 1 - ${QUICKENER_ARGLAUNCH} - --global-timeout ${PANDA_CTS_TESTING_TIMEOUT} - --timeout ${PANDA_CTS_TEST_TIMEOUT} - -j ${PANDA_CTS_JOBS_NUMBER} - --verifier-config "${PROJECT_BINARY_DIR}/verifier.config" - ${CTS_TEST_PRLIMIT_OPTIONS} - ${CTS_TEST_SELECT_OPTION_ARGS} VERBATIM - COMMAND ${CTS_TEST_RUNNER} - -t "${CTS_GENERATED_DIR}" - -p "${PROJECT_BINARY_DIR}/../../" - -x "${CTS_TEMP_DIR}" - -v 1 - -o "--interpreter-type=cpp" + -o "--compiler-enable-jit=false" ${QUICKENER_ARGLAUNCH} --global-timeout ${PANDA_CTS_TESTING_TIMEOUT} --timeout ${PANDA_CTS_TEST_TIMEOUT} @@ -178,21 +166,6 @@ if(NOT CMAKE_CROSSCOMPILING) ${CTS_TEST_PRLIMIT_OPTIONS} --exclude-tag verifier ${CTS_TEST_SELECT_OPTION_ARGS} VERBATIM - COMMAND ${CTS_TEST_RUNNER} - -t "${CTS_GENERATED_DIR}" - -p "${PROJECT_BINARY_DIR}/../../" - -x "${CTS_TEMP_DIR}" - -v 1 - ${QUICKENER_ARGLAUNCH} - --global-timeout ${PANDA_CTS_TESTING_TIMEOUT} - --timeout ${PANDA_CTS_TEST_TIMEOUT} - -j ${PANDA_CTS_JOBS_NUMBER} - --verifier-config "${PROJECT_BINARY_DIR}/verifier.config" - -o "--compiler-hotness-threshold=0" - -o "--no-async-jit" - ${CTS_TEST_PRLIMIT_OPTIONS} - --exclude-tag verifier - ${CTS_TEST_SELECT_OPTION_JIT_ARGS} VERBATIM DEPENDS "$" "$" "${TARGETFILE_ARKQUICK}" "$" "${OUTPUT_FILES}" ) -- Gitee From f052e008037114036d33d32a5a12df53a084f963 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Fri, 27 Sep 2024 16:17:32 +0300 Subject: [PATCH 14/36] [CI] Add 'expr_5.sts' to AOT ignore lists --- .../test-lists/ets-cts/ets-cts-ignored-AMD64-AOT.txt | 3 +++ .../test-lists/ets-cts/ets-cts-ignored-ARM64-AOT.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-AMD64-AOT.txt b/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-AMD64-AOT.txt index 4874bc64f..138b0a14b 100644 --- a/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-AMD64-AOT.txt +++ b/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-AMD64-AOT.txt @@ -1,3 +1,6 @@ +# LLVM AOT removes unused allocation +17.experimental_features/02.array_creation_expressions/01.runtime_evaluation_of_array_creation_expressions/expr_5.sts + # 17881 Skip these, because the run fails if multiple files are connected. The connection is necessary, because of the export tests. 13.compilation_units_packages_and_modules/04.import_directives/05.type_import_binding/type_binding_class.sts 13.compilation_units_packages_and_modules/04.import_directives/05.type_import_binding/type_binding_class_alias.sts diff --git a/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-ARM64-AOT.txt b/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-ARM64-AOT.txt index be70e269a..705a5b0bb 100644 --- a/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-ARM64-AOT.txt +++ b/static_core/tests/tests-u-runner/test-lists/ets-cts/ets-cts-ignored-ARM64-AOT.txt @@ -1,3 +1,6 @@ +# LLVM AOT removes unused allocation +17.experimental_features/02.array_creation_expressions/01.runtime_evaluation_of_array_creation_expressions/expr_5.sts + # 17881 Skip these, because the run fails if multiple files are connected. The connection is necessary, because of the export tests. 13.compilation_units_packages_and_modules/04.import_directives/05.type_import_binding/type_binding_class.sts 13.compilation_units_packages_and_modules/04.import_directives/05.type_import_binding/type_binding_class_alias.sts -- Gitee From fcb0335359ee734f0012825f161a6b053c8541fb Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Tue, 24 Sep 2024 18:55:49 +0300 Subject: [PATCH 15/36] Dump method name with signature --- static_core/compiler/tools/paoc/paoc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static_core/compiler/tools/paoc/paoc.cpp b/static_core/compiler/tools/paoc/paoc.cpp index e1b025265..57b0a4aef 100644 --- a/static_core/compiler/tools/paoc/paoc.cpp +++ b/static_core/compiler/tools/paoc/paoc.cpp @@ -64,7 +64,7 @@ void Paoc::CompilingContext::DumpStatistics() const { ASSERT(stats); char sep = ','; - *stats << method->GetFullName() << sep; + *stats << '"' << method->GetFullName(true) << '"' << sep; *stats << "paoc-summary" << sep; *stats << allocator.GetAllocatedSize() << sep; *stats << graphLocalAllocator.GetAllocatedSize() << '\n'; -- Gitee From 5cb9531acc25743f3966ea91764efd0303708f76 Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Tue, 24 Sep 2024 18:14:18 +0300 Subject: [PATCH 16/36] Detect missing llvm_codegen_func --- static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index c384c7a11..acd95c4d5 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -4725,6 +4725,7 @@ void LLVMIrConstructor::VisitIntrinsic(GraphVisitor *v, Inst *inst) return; } } + ASSERT(!EncodesBuiltin(ctor->GetGraph()->GetRuntime(), entryId, ctor->GetGraph()->GetArch())); // Create call otherwise auto result = ctor->CreateIntrinsicCall(inst); if (inst->GetType() != DataType::VOID) { -- Gitee From 316ebc939f723b2e68154be17c59f37a55cb637f Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Fri, 11 Oct 2024 20:02:04 +0300 Subject: [PATCH 17/36] Passes headers --- .../transforms/passes/aarch64_fixup_sdiv.h | 5 ++--- .../passes/ark_frame_lowering/frame_builder.h | 2 +- .../passes/ark_frame_lowering/frame_lowering.h | 2 +- .../libllvmbackend/transforms/passes/ark_gvn.h | 4 ++-- .../libllvmbackend/transforms/passes/ark_inlining.h | 6 +++--- .../transforms/passes/ark_speculation.h | 2 +- .../libllvmbackend/transforms/passes/check_external.h | 2 +- .../transforms/passes/check_tail_calls.h | 2 +- static_core/libllvmbackend/transforms/passes/devirt.h | 4 ++-- .../libllvmbackend/transforms/passes/expand_atomics.h | 2 +- .../libllvmbackend/transforms/passes/fixup_poisons.h | 2 +- .../libllvmbackend/transforms/passes/gc_intrusion.h | 4 ++-- .../transforms/passes/gc_intrusion_check.h | 4 ++-- .../transforms/passes/gep_propagation.h | 4 ++-- .../libllvmbackend/transforms/passes/infer_flags.cpp | 5 ----- .../libllvmbackend/transforms/passes/infer_flags.h | 11 +++++------ .../libllvmbackend/transforms/passes/inline_devirt.h | 8 ++++---- .../passes/inline_ir/cleanup_inline_module.h | 2 +- .../passes/inline_ir/discard_inline_module.cpp | 5 ----- .../passes/inline_ir/discard_inline_module.h | 7 +++++-- .../transforms/passes/inline_ir/mark_always_inline.h | 2 +- .../transforms/passes/inline_ir/mark_inline_module.h | 2 +- .../passes/inline_ir/remove_unused_functions.h | 2 +- .../transforms/passes/insert_safepoints.h | 8 ++------ .../transforms/passes/intrinsics_lowering.h | 5 ++--- .../libllvmbackend/transforms/passes/loop_peeling.cpp | 4 ---- .../libllvmbackend/transforms/passes/loop_peeling.h | 7 +++++-- .../libllvmbackend/transforms/passes/mem_barriers.cpp | 3 +-- .../libllvmbackend/transforms/passes/mem_barriers.h | 4 ++-- .../transforms/passes/panda_runtime_lowering.h | 7 +++---- .../transforms/passes/propagate_lenarray.cpp | 5 ----- .../transforms/passes/propagate_lenarray.h | 5 ++++- .../libllvmbackend/transforms/passes/prune_deopt.h | 4 ++-- 33 files changed, 61 insertions(+), 80 deletions(-) diff --git a/static_core/libllvmbackend/transforms/passes/aarch64_fixup_sdiv.h b/static_core/libllvmbackend/transforms/passes/aarch64_fixup_sdiv.h index 9f0624444..8587375bb 100644 --- a/static_core/libllvmbackend/transforms/passes/aarch64_fixup_sdiv.h +++ b/static_core/libllvmbackend/transforms/passes/aarch64_fixup_sdiv.h @@ -31,10 +31,9 @@ public: explicit AArch64FixupSDiv(LLVMArkInterface *arkInterface = nullptr); - static AArch64FixupSDiv Create(LLVMArkInterface *arkInterface, - const ark::llvmbackend::LLVMCompilerOptions *options); + static AArch64FixupSDiv Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } diff --git a/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_builder.h b/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_builder.h index db60c0223..57a98faca 100644 --- a/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_builder.h +++ b/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_builder.h @@ -115,4 +115,4 @@ private: std::string_view asmPairRegs, ssize_t calleeOffset); }; -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_ARK_FRAME_LOWERING_FRAME_BUILDER_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_ARK_FRAME_LOWERING_FRAME_BUILDER_H diff --git a/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_lowering.h b/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_lowering.h index 196315037..091af4d2c 100644 --- a/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_lowering.h +++ b/static_core/libllvmbackend/transforms/passes/ark_frame_lowering/frame_lowering.h @@ -27,4 +27,4 @@ class LLVMArkInterface; llvm::MachineFunctionPass *CreateFrameLoweringPass(LLVMArkInterface *arkInterface); } // namespace ark::llvmbackend -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_ARK_FRAME_LOWERING_FRAME_LOWERING_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_ARK_FRAME_LOWERING_FRAME_LOWERING_H diff --git a/static_core/libllvmbackend/transforms/passes/ark_gvn.h b/static_core/libllvmbackend/transforms/passes/ark_gvn.h index 6cd42904a..a2516a416 100644 --- a/static_core/libllvmbackend/transforms/passes/ark_gvn.h +++ b/static_core/libllvmbackend/transforms/passes/ark_gvn.h @@ -36,11 +36,11 @@ class ArkGVN : public llvm::PassInfoMixin { public: explicit ArkGVN(LLVMArkInterface *arkInterface = nullptr); - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } - static ArkGVN Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options); + static ArkGVN Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); diff --git a/static_core/libllvmbackend/transforms/passes/ark_inlining.h b/static_core/libllvmbackend/transforms/passes/ark_inlining.h index c67ebd57f..0391498f6 100644 --- a/static_core/libllvmbackend/transforms/passes/ark_inlining.h +++ b/static_core/libllvmbackend/transforms/passes/ark_inlining.h @@ -34,7 +34,7 @@ class IrtocInlineChecker : public llvm::PassInfoMixin { public: static constexpr llvm::StringRef ARG_NAME = "irtoc-inline-check"; - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); void CheckShouldInline(llvm::CallBase *callBase); // NOLINTNEXTLINE(readability-identifier-naming) @@ -49,8 +49,8 @@ public: static constexpr llvm::StringRef ARG_NAME = "inline-prepare"; explicit InlinePrepare(llvm::InlineParams inlineParams) : inlineParams_ {inlineParams} {} - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); - static InlinePrepare Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); + static InlinePrepare Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &moduleAm); diff --git a/static_core/libllvmbackend/transforms/passes/ark_speculation.h b/static_core/libllvmbackend/transforms/passes/ark_speculation.h index 112f9104c..e7d06dd21 100644 --- a/static_core/libllvmbackend/transforms/passes/ark_speculation.h +++ b/static_core/libllvmbackend/transforms/passes/ark_speculation.h @@ -32,7 +32,7 @@ public: static constexpr llvm::StringRef ARG_NAME = "wrap-speculative-execution"; explicit ArkSpeculativeExecution() : llvm::SpeculativeExecutionPass(ONLY_IF_DIVERGENT_TARGET) {} - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } diff --git a/static_core/libllvmbackend/transforms/passes/check_external.h b/static_core/libllvmbackend/transforms/passes/check_external.h index c599cf8e8..4706ec9e8 100644 --- a/static_core/libllvmbackend/transforms/passes/check_external.h +++ b/static_core/libllvmbackend/transforms/passes/check_external.h @@ -33,7 +33,7 @@ class CheckExternal : public llvm::PassInfoMixin { public: explicit CheckExternal() = default; - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); static CheckExternal Create(); diff --git a/static_core/libllvmbackend/transforms/passes/check_tail_calls.h b/static_core/libllvmbackend/transforms/passes/check_tail_calls.h index 9262ab3dd..c949f8371 100644 --- a/static_core/libllvmbackend/transforms/passes/check_tail_calls.h +++ b/static_core/libllvmbackend/transforms/passes/check_tail_calls.h @@ -26,4 +26,4 @@ namespace ark::llvmbackend { llvm::MachineFunctionPass *CreateCheckTailCallsPass(); } // namespace ark::llvmbackend -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_CHECK_TAIL_CALLS_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_CHECK_TAIL_CALLS_H diff --git a/static_core/libllvmbackend/transforms/passes/devirt.h b/static_core/libllvmbackend/transforms/passes/devirt.h index daabdfb69..d1db36422 100644 --- a/static_core/libllvmbackend/transforms/passes/devirt.h +++ b/static_core/libllvmbackend/transforms/passes/devirt.h @@ -38,9 +38,9 @@ class Devirt : public llvm::PassInfoMixin { public: explicit Devirt(LLVMArkInterface *arkInterface = nullptr); - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); - static Devirt Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options); + static Devirt Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); diff --git a/static_core/libllvmbackend/transforms/passes/expand_atomics.h b/static_core/libllvmbackend/transforms/passes/expand_atomics.h index b217ed558..92c27c71d 100644 --- a/static_core/libllvmbackend/transforms/passes/expand_atomics.h +++ b/static_core/libllvmbackend/transforms/passes/expand_atomics.h @@ -30,7 +30,7 @@ public: explicit ExpandAtomics(); - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } diff --git a/static_core/libllvmbackend/transforms/passes/fixup_poisons.h b/static_core/libllvmbackend/transforms/passes/fixup_poisons.h index f5d7adb2b..63ae3ef7e 100644 --- a/static_core/libllvmbackend/transforms/passes/fixup_poisons.h +++ b/static_core/libllvmbackend/transforms/passes/fixup_poisons.h @@ -31,7 +31,7 @@ public: explicit FixupPoisons(); - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } diff --git a/static_core/libllvmbackend/transforms/passes/gc_intrusion.h b/static_core/libllvmbackend/transforms/passes/gc_intrusion.h index e49795d03..ab5b0a566 100644 --- a/static_core/libllvmbackend/transforms/passes/gc_intrusion.h +++ b/static_core/libllvmbackend/transforms/passes/gc_intrusion.h @@ -30,7 +30,7 @@ class GcRefLiveness; class GcIntrusion : public llvm::PassInfoMixin { public: - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } @@ -96,4 +96,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_GC_INTRUSION_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_GC_INTRUSION_H diff --git a/static_core/libllvmbackend/transforms/passes/gc_intrusion_check.h b/static_core/libllvmbackend/transforms/passes/gc_intrusion_check.h index a01a1554e..f0e023eb7 100644 --- a/static_core/libllvmbackend/transforms/passes/gc_intrusion_check.h +++ b/static_core/libllvmbackend/transforms/passes/gc_intrusion_check.h @@ -33,7 +33,7 @@ class GcIntrusionCheck : public llvm::PassInfoMixin { public: static constexpr llvm::StringRef ARG_NAME = "gc-intrusion-check"; - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); @@ -57,4 +57,4 @@ private: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_GC_INTRUSION_CHECK_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_GC_INTRUSION_CHECK_H diff --git a/static_core/libllvmbackend/transforms/passes/gep_propagation.h b/static_core/libllvmbackend/transforms/passes/gep_propagation.h index 1fa0421fd..ca3b9b162 100644 --- a/static_core/libllvmbackend/transforms/passes/gep_propagation.h +++ b/static_core/libllvmbackend/transforms/passes/gep_propagation.h @@ -31,7 +31,7 @@ namespace ark::llvmbackend::passes { class GepPropagation : public llvm::PassInfoMixin { public: - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } @@ -77,4 +77,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_GEP_PROPAGATION_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_GEP_PROPAGATION_H diff --git a/static_core/libllvmbackend/transforms/passes/infer_flags.cpp b/static_core/libllvmbackend/transforms/passes/infer_flags.cpp index 233642e57..99679c640 100644 --- a/static_core/libllvmbackend/transforms/passes/infer_flags.cpp +++ b/static_core/libllvmbackend/transforms/passes/infer_flags.cpp @@ -58,11 +58,6 @@ bool CanOverflow(const llvm::KnownBits &start, const llvm::KnownBits &step, uint namespace ark::llvmbackend::passes { -bool InferFlags::ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) -{ - return true; -} - llvm::PreservedAnalyses InferFlags::run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager) { LLVM_DEBUG(llvm::dbgs() << "Running on '" << function.getName() << "'\n"); diff --git a/static_core/libllvmbackend/transforms/passes/infer_flags.h b/static_core/libllvmbackend/transforms/passes/infer_flags.h index cee7c3784..3c196a808 100644 --- a/static_core/libllvmbackend/transforms/passes/infer_flags.h +++ b/static_core/libllvmbackend/transforms/passes/infer_flags.h @@ -24,10 +24,6 @@ namespace ark::llvmbackend { struct LLVMCompilerOptions; } // namespace ark::llvmbackend -namespace ark::llvmbackend { -class LLVMArkInterface; -} // namespace ark::llvmbackend - namespace ark::llvmbackend::passes { /// Simple pass, that infers "nsw" flag (no signed wrap) to help llvm perform optimizations @@ -35,7 +31,10 @@ class InferFlags : public llvm::PassInfoMixin { public: explicit InferFlags() = default; - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) + { + return true; + } // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); @@ -51,4 +50,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_INFER_FLAGS_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_INFER_FLAGS_H diff --git a/static_core/libllvmbackend/transforms/passes/inline_devirt.h b/static_core/libllvmbackend/transforms/passes/inline_devirt.h index 74286c674..221efc544 100644 --- a/static_core/libllvmbackend/transforms/passes/inline_devirt.h +++ b/static_core/libllvmbackend/transforms/passes/inline_devirt.h @@ -28,9 +28,9 @@ class InlineDevirt : public llvm::PassInfoMixin { public: explicit InlineDevirt(LLVMArkInterface *arkInterface = nullptr, bool doVirtualInline = true); - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); - static InlineDevirt Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options); + static InlineDevirt Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::LazyCallGraph::SCC &initialSCC, llvm::CGSCCAnalysisManager &analysisManager, @@ -52,8 +52,8 @@ public: private: bool RunInlining(llvm::InlinerPass &inlinePass, llvm::SmallPtrSetImpl &changedFunctions); - bool RunDevirt(ark::llvmbackend::passes::Devirt &devirtPass); - void RunCheckExternal(ark::llvmbackend::passes::CheckExternal &externalPass); + bool RunDevirt(Devirt &devirtPass); + void RunCheckExternal(CheckExternal &externalPass); }; } // namespace ark::llvmbackend::passes diff --git a/static_core/libllvmbackend/transforms/passes/inline_ir/cleanup_inline_module.h b/static_core/libllvmbackend/transforms/passes/inline_ir/cleanup_inline_module.h index 6a24a6210..90ac3d272 100644 --- a/static_core/libllvmbackend/transforms/passes/inline_ir/cleanup_inline_module.h +++ b/static_core/libllvmbackend/transforms/passes/inline_ir/cleanup_inline_module.h @@ -38,7 +38,7 @@ public: ~CleanupInlineModule(); - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &analysis_manager); diff --git a/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.cpp b/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.cpp index 92e84884b..0da26fc01 100644 --- a/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.cpp +++ b/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.cpp @@ -31,11 +31,6 @@ using llvm::convertToDeclaration; namespace ark::llvmbackend::passes { -bool DiscardInlineModule::ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) -{ - return true; -} - /// Discard all functions and global variables from inline module llvm::PreservedAnalyses DiscardInlineModule::run(llvm::Module &module, llvm::ModuleAnalysisManager & /*AM*/) { diff --git a/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.h b/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.h index b2b836ca2..9067f0dd1 100644 --- a/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.h +++ b/static_core/libllvmbackend/transforms/passes/inline_ir/discard_inline_module.h @@ -30,7 +30,10 @@ namespace ark::llvmbackend::passes { class DiscardInlineModule : public llvm::PassInfoMixin { public: - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) + { + return true; + } // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &analysis_manager); @@ -46,4 +49,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_INLINE_IR_DISCARD_INLINE_MODULE_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_INLINE_IR_DISCARD_INLINE_MODULE_H diff --git a/static_core/libllvmbackend/transforms/passes/inline_ir/mark_always_inline.h b/static_core/libllvmbackend/transforms/passes/inline_ir/mark_always_inline.h index 215263cf1..bb83a4087 100644 --- a/static_core/libllvmbackend/transforms/passes/inline_ir/mark_always_inline.h +++ b/static_core/libllvmbackend/transforms/passes/inline_ir/mark_always_inline.h @@ -31,7 +31,7 @@ namespace ark::llvmbackend::passes { */ class MarkAlwaysInline : public llvm::PassInfoMixin { public: - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysis_manager); diff --git a/static_core/libllvmbackend/transforms/passes/inline_ir/mark_inline_module.h b/static_core/libllvmbackend/transforms/passes/inline_ir/mark_inline_module.h index 491ea8047..6c0c52f6a 100644 --- a/static_core/libllvmbackend/transforms/passes/inline_ir/mark_inline_module.h +++ b/static_core/libllvmbackend/transforms/passes/inline_ir/mark_inline_module.h @@ -30,7 +30,7 @@ namespace ark::llvmbackend::passes { class MarkInlineModule : public llvm::PassInfoMixin { public: - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &analysis_manager); diff --git a/static_core/libllvmbackend/transforms/passes/inline_ir/remove_unused_functions.h b/static_core/libllvmbackend/transforms/passes/inline_ir/remove_unused_functions.h index 4ff01bbd8..9b4f42b3a 100644 --- a/static_core/libllvmbackend/transforms/passes/inline_ir/remove_unused_functions.h +++ b/static_core/libllvmbackend/transforms/passes/inline_ir/remove_unused_functions.h @@ -39,7 +39,7 @@ namespace ark::llvmbackend::passes { */ class RemoveUnusedFunctions : public llvm::PassInfoMixin { public: - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Module &module, llvm::ModuleAnalysisManager &analysis_manager); diff --git a/static_core/libllvmbackend/transforms/passes/insert_safepoints.h b/static_core/libllvmbackend/transforms/passes/insert_safepoints.h index 59e9c801d..7e45db00f 100644 --- a/static_core/libllvmbackend/transforms/passes/insert_safepoints.h +++ b/static_core/libllvmbackend/transforms/passes/insert_safepoints.h @@ -22,17 +22,13 @@ namespace ark::llvmbackend { struct LLVMCompilerOptions; } // namespace ark::llvmbackend -namespace ark::llvmbackend { -class LLVMArkInterface; -} // namespace ark::llvmbackend - namespace ark::llvmbackend::passes { class InsertSafepoints : public llvm::PassInfoMixin { public: explicit InsertSafepoints() = default; - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert(const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); @@ -43,4 +39,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_INSERT_SAFEPOINTS_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_INSERT_SAFEPOINTS_H diff --git a/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.h b/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.h index 4ea00f59b..4a64f8d6c 100644 --- a/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.h +++ b/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.h @@ -38,13 +38,12 @@ class IntrinsicsLowering : public llvm::PassInfoMixin { public: explicit IntrinsicsLowering(LLVMArkInterface *arkInterface = nullptr); - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } - static IntrinsicsLowering Create(LLVMArkInterface *arkInterface, - const ark::llvmbackend::LLVMCompilerOptions *options); + static IntrinsicsLowering Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); diff --git a/static_core/libllvmbackend/transforms/passes/loop_peeling.cpp b/static_core/libllvmbackend/transforms/passes/loop_peeling.cpp index 433ed2e9c..f617fab11 100644 --- a/static_core/libllvmbackend/transforms/passes/loop_peeling.cpp +++ b/static_core/libllvmbackend/transforms/passes/loop_peeling.cpp @@ -68,8 +68,4 @@ bool ArkLoopPeeling::ContainsDeoptimize(llvm::Loop *loop) return false; } -bool ArkLoopPeeling::ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) -{ - return true; -} } // namespace ark::llvmbackend::passes diff --git a/static_core/libllvmbackend/transforms/passes/loop_peeling.h b/static_core/libllvmbackend/transforms/passes/loop_peeling.h index 1f12c37e9..9254a5cfb 100644 --- a/static_core/libllvmbackend/transforms/passes/loop_peeling.h +++ b/static_core/libllvmbackend/transforms/passes/loop_peeling.h @@ -39,7 +39,10 @@ public: explicit ArkLoopPeeling() = default; - static bool ShouldInsert(const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) + { + return true; + } private: bool ContainsDeoptimize(llvm::Loop *loop); @@ -50,4 +53,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_LOOP_PEELING_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_LOOP_PEELING_H diff --git a/static_core/libllvmbackend/transforms/passes/mem_barriers.cpp b/static_core/libllvmbackend/transforms/passes/mem_barriers.cpp index 765111a44..2e6996feb 100644 --- a/static_core/libllvmbackend/transforms/passes/mem_barriers.cpp +++ b/static_core/libllvmbackend/transforms/passes/mem_barriers.cpp @@ -29,8 +29,7 @@ using llvm::Instruction; namespace ark::llvmbackend::passes { -MemBarriers MemBarriers::Create([[maybe_unused]] LLVMArkInterface *arkInterface, - const ark::llvmbackend::LLVMCompilerOptions *options) +MemBarriers MemBarriers::Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options) { return MemBarriers(arkInterface, options->optimize); } diff --git a/static_core/libllvmbackend/transforms/passes/mem_barriers.h b/static_core/libllvmbackend/transforms/passes/mem_barriers.h index 2f25c88b6..29285d7d7 100644 --- a/static_core/libllvmbackend/transforms/passes/mem_barriers.h +++ b/static_core/libllvmbackend/transforms/passes/mem_barriers.h @@ -30,12 +30,12 @@ class MemBarriers : public llvm::PassInfoMixin { public: explicit MemBarriers(LLVMArkInterface *arkInterface, bool optimize); - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } - static MemBarriers Create(LLVMArkInterface *arkInterface, const ark::llvmbackend::LLVMCompilerOptions *options); + static MemBarriers Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); diff --git a/static_core/libllvmbackend/transforms/passes/panda_runtime_lowering.h b/static_core/libllvmbackend/transforms/passes/panda_runtime_lowering.h index 26c7bebbd..51270d2f7 100644 --- a/static_core/libllvmbackend/transforms/passes/panda_runtime_lowering.h +++ b/static_core/libllvmbackend/transforms/passes/panda_runtime_lowering.h @@ -35,13 +35,12 @@ class PandaRuntimeLowering : public llvm::PassInfoMixin { public: explicit PandaRuntimeLowering(LLVMArkInterface *arkInterface = nullptr); - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } - static PandaRuntimeLowering Create(LLVMArkInterface *arkInterface, - const ark::llvmbackend::LLVMCompilerOptions *options); + static PandaRuntimeLowering Create(LLVMArkInterface *arkInterface, const LLVMCompilerOptions *options); // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &am); @@ -63,4 +62,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_PANDA_RUNTIME_LOWERING_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_PANDA_RUNTIME_LOWERING_H diff --git a/static_core/libllvmbackend/transforms/passes/propagate_lenarray.cpp b/static_core/libllvmbackend/transforms/passes/propagate_lenarray.cpp index 6bc06f189..5c1f907ed 100644 --- a/static_core/libllvmbackend/transforms/passes/propagate_lenarray.cpp +++ b/static_core/libllvmbackend/transforms/passes/propagate_lenarray.cpp @@ -33,11 +33,6 @@ namespace ark::llvmbackend::passes { -bool PropagateLenArray::ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) -{ - return true; -} - llvm::PreservedAnalyses PropagateLenArray::run(llvm::Function &function, [[maybe_unused]] llvm::FunctionAnalysisManager &analysisManager) { diff --git a/static_core/libllvmbackend/transforms/passes/propagate_lenarray.h b/static_core/libllvmbackend/transforms/passes/propagate_lenarray.h index 96635803c..4559aed61 100644 --- a/static_core/libllvmbackend/transforms/passes/propagate_lenarray.h +++ b/static_core/libllvmbackend/transforms/passes/propagate_lenarray.h @@ -31,7 +31,10 @@ public: explicit PropagateLenArray() = default; - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options); + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) + { + return true; + } // NOLINTNEXTLINE(readability-identifier-naming) llvm::PreservedAnalyses run(llvm::Function &function, llvm::FunctionAnalysisManager &analysisManager); diff --git a/static_core/libllvmbackend/transforms/passes/prune_deopt.h b/static_core/libllvmbackend/transforms/passes/prune_deopt.h index 99b94278d..1692e6ba0 100644 --- a/static_core/libllvmbackend/transforms/passes/prune_deopt.h +++ b/static_core/libllvmbackend/transforms/passes/prune_deopt.h @@ -30,7 +30,7 @@ namespace ark::llvmbackend::passes { class PruneDeopt : public llvm::PassInfoMixin { public: - static bool ShouldInsert([[maybe_unused]] const ark::llvmbackend::LLVMCompilerOptions *options) + static bool ShouldInsert([[maybe_unused]] const LLVMCompilerOptions *options) { return true; } @@ -59,4 +59,4 @@ public: } // namespace ark::llvmbackend::passes -#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_PRUNE_DEOPT_H +#endif // LIBLLVMBACKEND_TRANSFORMS_PASSES_PRUNE_DEOPT_H -- Gitee From 70e692758407aeaeab83af4520ac5ea6e23c7b57 Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Sat, 2 Nov 2024 17:59:26 +0300 Subject: [PATCH 18/36] Fix 'CreateLaunchArgsArray' in LLVM AOT Make sure that llvm aot stores pointer to reference with zeroed high part of 64-bit args slot Signed-off-by: Denis Zavedeev --- static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index acd95c4d5..fef73ab5b 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -2213,8 +2213,9 @@ llvm::Value *LLVMIrConstructor::CreateLaunchArgsArray(CallInst *callInst, uint32 auto typeSize = DataType::GetTypeSize(type, GetGraph()->GetArch()); if (typeSize < DataType::GetTypeSize(DataType::INT32, GetGraph()->GetArch())) { arg = CoerceValue(arg, type, DataType::INT32); + } else if (type == DataType::REFERENCE) { + arg = builder_.CreatePtrToInt(arg, builder_.getInt64Ty()); } - auto gep = builder_.CreateConstInBoundsGEP1_32(builder_.getInt64Ty(), callArgs, i); builder_.CreateStore(arg, gep); } -- Gitee From 59c1025fa6bbaa2939daf16b541387553ce4a284 Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Thu, 31 Oct 2024 12:48:12 +0300 Subject: [PATCH 19/36] Introduce PreWrb FastPath wrapper Signed-off-by: Denis Zavedeev --- static_core/irtoc/scripts/gc.irt | 13 ++++ .../libllvmbackend/lowering/gc_barriers.cpp | 66 +++++++++++++++++-- .../libllvmbackend/lowering/gc_barriers.h | 2 +- .../lowering/llvm_ir_constructor.cpp | 6 +- .../templates/llvm_passes.inl.erb | 6 +- .../libllvmbackend/transforms/builtins.cpp | 3 +- static_core/libllvmbackend/utils.cpp | 16 +++++ static_core/libllvmbackend/utils.h | 1 + .../runtime/entrypoints/entrypoints.yaml | 8 +++ 9 files changed, 109 insertions(+), 12 deletions(-) diff --git a/static_core/irtoc/scripts/gc.irt b/static_core/irtoc/scripts/gc.irt index 36e010a1f..c748098b1 100644 --- a/static_core/irtoc/scripts/gc.irt +++ b/static_core/irtoc/scripts/gc.irt @@ -27,6 +27,19 @@ function(:EmptyPostWriteBarrier, ReturnVoid().void } +# wrapper over the PreWrb function to avoid +# the prologue bloating in the caller +function(:PreWrbInterposer, + params: {mem: 'ref'}, + mode: [:FastPath]) { + if Options.arch == :arm32 + Intrinsic(:UNREACHABLE).Terminator.void + next + end + Call(mem).Method("PreWrbFuncEntrypoint").void + ReturnVoid().void +} + def PostInterGenerationalBarrier(obj_num) if obj_num == 0 params = {mem: 'ref_uint'} diff --git a/static_core/libllvmbackend/lowering/gc_barriers.cpp b/static_core/libllvmbackend/lowering/gc_barriers.cpp index bab5986e7..c2c5c9387 100644 --- a/static_core/libllvmbackend/lowering/gc_barriers.cpp +++ b/static_core/libllvmbackend/lowering/gc_barriers.cpp @@ -19,6 +19,7 @@ #include "metadata.h" #include "transforms/builtins.h" #include "transforms/runtime_calls.h" +#include "utils.h" #include "compiler/optimizer/ir/basicblock.h" @@ -27,9 +28,66 @@ #include namespace ark::llvmbackend::gc_barriers { +namespace { +inline llvm::Function *GetOrDeclarePreWrbinterposer(llvm::FunctionType *functionType, llvm::Module *module) +{ + ASSERT(functionType != nullptr); + ASSERT(module != nullptr); + constexpr llvm::StringRef NAME = "PreWrbInterposer"; + + auto function = module->getFunction(NAME); + if (function != nullptr) { + ASSERT(function->doesNotThrow()); + ASSERT(function->getVisibility() == llvm::GlobalValue::ProtectedVisibility); + ASSERT(function->getCallingConv() == llvm::CallingConv::ArkFast1); + return function; + } + + function = llvm::Function::Create(functionType, llvm::Function::ExternalLinkage, NAME, module); + function->setDoesNotThrow(); + function->setVisibility(llvm::GlobalValue::ProtectedVisibility); + function->setSectionPrefix(NAME); + function->setCallingConv(llvm::CallingConv::ArkFast1); + + return function; +} + +void CreatePreWrbCall(llvm::IRBuilder<> *builder, LLVMArkInterface *arkInterface, llvm::Value *threadRegValue, + llvm::Value *frameRegValue, llvm::LoadInst *entrypoint, llvm::Value *load) +{ + constexpr auto VAR_ARGS = true; + auto *func = builder->GetInsertBlock()->getParent(); + auto *module = func->getParent(); + auto *ptrType = builder->getPtrTy(); + auto *ptrGcType = builder->getPtrTy(LLVMArkInterface::GC_ADDR_SPACE); + auto *voidType = builder->getVoidTy(); + + if (!arkInterface->IsIrtocMode()) { + // AoT mode, call PreWrbEntrypoint + ASSERT(frameRegValue == nullptr); + auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType}, !VAR_ARGS); + [[maybe_unused]] auto *call = builder->CreateCall(functionType, entrypoint, {load}); + ASSERT(call->getCallingConv() == llvm::CallingConv::C); + return; + } + if (frameRegValue != nullptr) { + ASSERT(utils::IsFastPath(func) || !arkInterface->IsArm64()); + auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType, ptrType, ptrType}, !VAR_ARGS); + auto *callee = GetOrDeclarePreWrbinterposer(functionType, module); + auto *call = builder->CreateCall(callee, {load, threadRegValue, frameRegValue}); + call->setCallingConv(llvm::CallingConv::ArkFast1); + return; + } + ASSERT(arkInterface->IsArm64()); + auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType, ptrType}, !VAR_ARGS); + auto *callee = GetOrDeclarePreWrbinterposer(functionType, module); + auto *call = builder->CreateCall(callee, {load, threadRegValue}); + call->setCallingConv(llvm::CallingConv::ArkFast1); +} +} // namespace void EmitPreWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, bool isVolatileMem, llvm::BasicBlock *outBb, - LLVMArkInterface *arkInterface, llvm::Value *threadRegValue) + LLVMArkInterface *arkInterface, llvm::Value *threadRegValue, llvm::Value *frameRegValue) { auto func = builder->GetInsertBlock()->getParent(); auto module = func->getParent(); @@ -70,12 +128,8 @@ void EmitPreWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, bool isVolatileMem // Call Runtime builder->SetInsertPoint(callRuntimeBb); - static constexpr auto VAR_ARGS = true; - auto functionType = - llvm::FunctionType::get(builder->getVoidTy(), {builder->getPtrTy(LLVMArkInterface::GC_ADDR_SPACE)}, !VAR_ARGS); - builder->CreateCall(functionType, entrypoint, {load}); + CreatePreWrbCall(builder, arkInterface, threadRegValue, frameRegValue, entrypoint, load); builder->CreateBr(outBb); - builder->SetInsertPoint(outBb); } diff --git a/static_core/libllvmbackend/lowering/gc_barriers.h b/static_core/libllvmbackend/lowering/gc_barriers.h index 5d8c70d65..639384831 100644 --- a/static_core/libllvmbackend/lowering/gc_barriers.h +++ b/static_core/libllvmbackend/lowering/gc_barriers.h @@ -24,7 +24,7 @@ class LLVMArkInterface; namespace ark::llvmbackend::gc_barriers { void EmitPreWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, bool isVolatileMem, llvm::BasicBlock *outBb, - LLVMArkInterface *arkInterface, llvm::Value *threadRegValue); + LLVMArkInterface *arkInterface, llvm::Value *threadRegValue, llvm::Value *frameRegValue); void EmitPostWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, llvm::Value *offset, llvm::Value *value, LLVMArkInterface *arkInterface, llvm::Value *threadRegValue, llvm::Value *frameRegValue); diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index fef73ab5b..b542a5086 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -2460,7 +2460,11 @@ void LLVMIrConstructor::CreatePreWRB(Inst *inst, llvm::Value *mem) } auto &ctx = func_->getContext(); auto outBb = llvm::BasicBlock::Create(ctx, CreateBasicBlockName(inst, "pre_wrb_out"), func_); - llvmbackend::gc_barriers::EmitPreWRB(&builder_, mem, isVolatile, outBb, arkInterface_, GetThreadRegValue()); + + bool needFrame = + arkInterface_->IsIrtocMode() && (GetGraph()->GetArch() == Arch::X86_64 || GetGraph()->GetMode().IsFastPath()); + auto frame = needFrame ? GetRealFrameRegValue() : nullptr; + llvmbackend::gc_barriers::EmitPreWRB(&builder_, mem, isVolatile, outBb, arkInterface_, GetThreadRegValue(), frame); } void LLVMIrConstructor::CreatePostWRB(Inst *inst, llvm::Value *mem, llvm::Value *offset, llvm::Value *value) diff --git a/static_core/libllvmbackend/templates/llvm_passes.inl.erb b/static_core/libllvmbackend/templates/llvm_passes.inl.erb index 75b0dba4b..6dbfc7969 100644 --- a/static_core/libllvmbackend/templates/llvm_passes.inl.erb +++ b/static_core/libllvmbackend/templates/llvm_passes.inl.erb @@ -40,7 +40,7 @@ public: bool ParseModulePasses(StringRef name, llvm::ModulePassManager &modulePm, const LLVMCompilerOptions &options); bool ParseFunctionPasses(StringRef name, llvm::FunctionPassManager &functionPm, const LLVMCompilerOptions &options); bool ParseSCCPasses(StringRef name, llvm::CGSCCPassManager &sccPm, const LLVMCompilerOptions &options); - bool ParseLoopPasses(StringRef name, llvm::LoopPassManager &sccPm, const LLVMCompilerOptions &options); + bool ParseLoopPasses(StringRef name, llvm::LoopPassManager &loopPm, const LLVMCompilerOptions &options); void RegisterParserCallbacks(llvm::PassBuilder &builder, const ark::llvmbackend::LLVMCompilerOptions &options) { @@ -57,8 +57,8 @@ public: return ParseSCCPasses(name, sccPm, options); }); builder.registerPipelineParsingCallback( - [&](StringRef name, llvm::LoopPassManager &sccPm, PipelineElements /*unused*/) -> bool { - return ParseLoopPasses(name, sccPm, options); + [&](StringRef name, llvm::LoopPassManager &loopPm, PipelineElements /*unused*/) -> bool { + return ParseLoopPasses(name, loopPm, options); }); } private: diff --git a/static_core/libllvmbackend/transforms/builtins.cpp b/static_core/libllvmbackend/transforms/builtins.cpp index ca1633a05..649170a48 100644 --- a/static_core/libllvmbackend/transforms/builtins.cpp +++ b/static_core/libllvmbackend/transforms/builtins.cpp @@ -177,7 +177,8 @@ llvm::Value *PreWRBHelper(llvm::IRBuilder<> *builder, llvm::CallInst *inst, LLVM initialBb->back().eraseFromParent(); builder->SetInsertPoint(initialBb); auto threadRegValue = GetThreadRegValue(builder, arkInterface); - ark::llvmbackend::gc_barriers::EmitPreWRB(builder, mem, isVolatileMem, continuation, arkInterface, threadRegValue); + ark::llvmbackend::gc_barriers::EmitPreWRB(builder, mem, isVolatileMem, continuation, arkInterface, threadRegValue, + nullptr); return nullptr; } } // namespace diff --git a/static_core/libllvmbackend/utils.cpp b/static_core/libllvmbackend/utils.cpp index dc58a6314..6a52bdeb9 100644 --- a/static_core/libllvmbackend/utils.cpp +++ b/static_core/libllvmbackend/utils.cpp @@ -89,4 +89,20 @@ llvm::Value *CreateLoadMethodUsingVTable(llvm::Value *thiz, llvm::Function *call return builder->CreateLoad(builder->getPtrTy(), methodPtr); } +bool IsFastPath(llvm::Function *func) +{ + switch (func->getCallingConv()) { + case llvm::CallingConv::ArkFast0: + case llvm::CallingConv::ArkFast1: + case llvm::CallingConv::ArkFast2: + case llvm::CallingConv::ArkFast3: + case llvm::CallingConv::ArkFast4: + case llvm::CallingConv::ArkFast5: + case llvm::CallingConv::ArkFast6: + return true; + default: + return false; + } +} + } // namespace ark::llvmbackend::utils diff --git a/static_core/libllvmbackend/utils.h b/static_core/libllvmbackend/utils.h index f63ce60c4..0192e8f45 100644 --- a/static_core/libllvmbackend/utils.h +++ b/static_core/libllvmbackend/utils.h @@ -30,6 +30,7 @@ llvm::Value *CreateLoadClassFromObject(llvm::Value *object, llvm::IRBuilder<> *b ark::llvmbackend::LLVMArkInterface *arkInterface); llvm::Value *CreateLoadMethodUsingVTable(llvm::Value *thiz, llvm::Function *caller, size_t methodId, llvm::IRBuilder<> *builder, LLVMArkInterface *arkInterface); +bool IsFastPath(llvm::Function *func); } // namespace ark::llvmbackend::utils diff --git a/static_core/runtime/entrypoints/entrypoints.yaml b/static_core/runtime/entrypoints/entrypoints.yaml index f1d3c551f..67000f3b9 100644 --- a/static_core/runtime/entrypoints/entrypoints.yaml +++ b/static_core/runtime/entrypoints/entrypoints.yaml @@ -705,6 +705,14 @@ entrypoints: - void - ark::ObjectHeader* +- name: PreWrbInterposer # "bridge" to avoid generating the excessive prologue + entrypoint: PreWrbInterposer + bridge: none + properties: [irtoc] + signature: + - void + - ark::ObjectHeader* + - name: MonitorEnterOddSaved entrypoint: LockObjectSlowPathEntrypoint bridge: odd_saved -- Gitee From f04cba02e0003447d5e944cc10a1c16cd2ce90c9 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Wed, 6 Nov 2024 11:49:23 +0300 Subject: [PATCH 20/36] Fix for check-tail-calls pass --- .../libllvmbackend/transforms/passes/check_tail_calls.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/static_core/libllvmbackend/transforms/passes/check_tail_calls.cpp b/static_core/libllvmbackend/transforms/passes/check_tail_calls.cpp index d5ac10ac3..ecac9d21c 100644 --- a/static_core/libllvmbackend/transforms/passes/check_tail_calls.cpp +++ b/static_core/libllvmbackend/transforms/passes/check_tail_calls.cpp @@ -117,6 +117,9 @@ public: [&instInfo](llvm::MachineInstr &term) { return instInfo->isTailCall(term); })) { return true; } + if (basicBlock->succ_empty()) { + return false; + } if (visitedBasicBlocks->contains(basicBlock)) { llvm::report_fatal_error("Cycle in CFG in '" + basicBlock->getParent()->getName() + "' prevents tail call check"); -- Gitee From 4a2fdc33998387d4740ba3f72eb49aa7b10bd31a Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Thu, 7 Nov 2024 19:51:57 +0300 Subject: [PATCH 21/36] Take method return type for IrToc from tail calls Signed-off-by: Denis Zavedeev --- static_core/irtoc/backend/irtoc_runtime.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/static_core/irtoc/backend/irtoc_runtime.h b/static_core/irtoc/backend/irtoc_runtime.h index 957072e85..2ecc9f688 100644 --- a/static_core/irtoc/backend/irtoc_runtime.h +++ b/static_core/irtoc/backend/irtoc_runtime.h @@ -69,10 +69,15 @@ public: if (exit->IsEmpty()) { continue; } - auto last = exit->GetLastInst(); - if (last->IsReturn()) { - ASSERT(retType == compiler::DataType::NO_TYPE || retType == last->GetType()); - retType = last->GetType(); + for (auto inst : exit->Insts()) { + IntrinsicId id = inst->IsIntrinsic() ? inst->CastToIntrinsic()->GetIntrinsicId() : IntrinsicId::INVALID; + auto tailCall = id == IntrinsicId::INTRINSIC_SLOW_PATH_ENTRY || id == IntrinsicId::INTRINSIC_TAIL_CALL; + if (inst->IsReturn() || tailCall) { + // Check for return type mismatches, allow mismatch for dynamic methods + ASSERT(unit->GetGraph()->IsDynamicMethod() || retType == compiler::DataType::NO_TYPE || + retType == inst->GetType()); + retType = inst->GetType(); + } } } return retType; -- Gitee From 43ece34ebbfb429e250402c82475fbafe64b9480 Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Thu, 7 Nov 2024 19:52:13 +0300 Subject: [PATCH 22/36] [CI] Enable tracing in build_sdk.sh Signed-off-by: Denis Zavedeev --- static_core/scripts/sdk/build_sdk.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/static_core/scripts/sdk/build_sdk.sh b/static_core/scripts/sdk/build_sdk.sh index 09ef67202..b721550db 100755 --- a/static_core/scripts/sdk/build_sdk.sh +++ b/static_core/scripts/sdk/build_sdk.sh @@ -13,6 +13,7 @@ # limitations under the License. set -eo pipefail +set -x export SCRIPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" export ARK_ROOT="$SCRIPT_DIR/../.." -- Gitee From 25c9fd17ec7cae27bac7d6fc518a0e3b5ff01cda Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Fri, 8 Nov 2024 14:18:10 +0300 Subject: [PATCH 23/36] Enable more ets tests Signed-off-by: Denis Zavedeev --- .../plugins/ets/tests/ets_test_suite/CMakeLists.txt | 10 +++++----- .../ets/tests/ets_test_suite/containers/CMakeLists.txt | 2 +- .../ets/tests/ets_test_suite/coroutines/CMakeLists.txt | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/static_core/plugins/ets/tests/ets_test_suite/CMakeLists.txt b/static_core/plugins/ets/tests/ets_test_suite/CMakeLists.txt index cdf84a5f6..b1806c4d4 100644 --- a/static_core/plugins/ets/tests/ets_test_suite/CMakeLists.txt +++ b/static_core/plugins/ets/tests/ets_test_suite/CMakeLists.txt @@ -45,12 +45,12 @@ function(add_ets_test test_suite) set(target ${test_suite}_${ARG_TEST_NAME}-ets-aot) LIST(APPEND targets ${target}) run_aot_ets_code(aot ${test_in} ${test_out_dir} ${target} RUNTIME_EXTRA_OPTIONS ${ARG_OPTIONS}) - endif() - if ("LLVMAOT" IN_LIST ARG_MODE AND PANDA_LLVM_AOT) - set(target ${test_suite}_${ARG_TEST_NAME}-ets-llvmaot) - LIST(APPEND targets ${target}) - run_aot_ets_code(llvm ${test_in} ${test_out_dir} ${target} RUNTIME_EXTRA_OPTIONS ${ARG_OPTIONS}) + if (PANDA_LLVM_AOT) + set(llvm_target ${test_suite}_${ARG_TEST_NAME}-ets-llvmaot) + LIST(APPEND targets ${llvm_target}) + run_aot_ets_code(llvm ${test_in} ${test_out_dir} ${llvm_target} RUNTIME_EXTRA_OPTIONS ${ARG_OPTIONS}) + endif() endif() if ("JIT" IN_LIST ARG_MODE) diff --git a/static_core/plugins/ets/tests/ets_test_suite/containers/CMakeLists.txt b/static_core/plugins/ets/tests/ets_test_suite/containers/CMakeLists.txt index 734be4679..c7fd0bec8 100644 --- a/static_core/plugins/ets/tests/ets_test_suite/containers/CMakeLists.txt +++ b/static_core/plugins/ets/tests/ets_test_suite/containers/CMakeLists.txt @@ -24,7 +24,7 @@ add_custom_target(ets_test_suite_containers) # OPTION_SETS_THREADED "DEFAULT" # OPTION_SETS_STACKFUL "DEFAULT" "JS" "POOL" "JS_POOL" # WORKERS "AUTO" "ONE" -# MODE "INT" "JIT" "AOT" "LLVMAOT" "JITOSR" +# MODE "INT" "JIT" "AOT" "JITOSR" # ) # SKIP_ARM32_COMPILER and OPTIONS will apply to all tests function(add_ets_containers_test) diff --git a/static_core/plugins/ets/tests/ets_test_suite/coroutines/CMakeLists.txt b/static_core/plugins/ets/tests/ets_test_suite/coroutines/CMakeLists.txt index cecb39207..b2fd259ba 100644 --- a/static_core/plugins/ets/tests/ets_test_suite/coroutines/CMakeLists.txt +++ b/static_core/plugins/ets/tests/ets_test_suite/coroutines/CMakeLists.txt @@ -24,7 +24,7 @@ add_custom_target(ets_test_suite_coroutines) # OPTION_SETS_THREADED "DEFAULT" # OPTION_SETS_STACKFUL "DEFAULT" "JS" "POOL" "JS_POOL" # WORKERS "AUTO" "ONE" -# MODE "INT" "JIT" "AOT" "LLVMAOT" "JITOSR" +# MODE "INT" "JIT" "AOT" "JITOSR" # ) # This funciont will create a number of tests as a cartesian product of IMPL, OPTION_SETS_${IMPL}, WORKERS, and MODES, e.g. # THREADED DEFAULT AUTO INT -- Gitee From 56c55469194c34a42c57b880e939d233a935065b Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Fri, 8 Nov 2024 16:24:12 +0300 Subject: [PATCH 24/36] [cut] Drop most of unrelated tests Signed-off-by: Denis Zavedeev --- static_core/assembler/CMakeLists.txt | 2 ++ static_core/disassembler/CMakeLists.txt | 2 ++ static_core/libpandabase/CMakeLists.txt | 2 ++ static_core/libpandafile/CMakeLists.txt | 5 ++--- static_core/libziparchive/CMakeLists.txt | 2 ++ .../ets/tests/ets_test_suite/gc/CMakeLists.txt | 3 +-- .../ets/tests/micro-benchmarks/CMakeLists.txt | 2 -- static_core/plugins/ets/tests/napi/CMakeLists.txt | 2 ++ .../plugins/ets/tests/runtime/tooling/CMakeLists.txt | 2 ++ static_core/runtime/CMakeLists.txt | 4 ++++ static_core/static_linker/CMakeLists.txt | 2 ++ static_core/tests/CMakeLists.txt | 4 ++++ static_core/tests/cts-generator/CMakeLists.txt | 12 ++++++------ static_core/tests/panda/CMakeLists.txt | 2 ++ static_core/verification/CMakeLists.txt | 2 ++ 15 files changed, 35 insertions(+), 13 deletions(-) diff --git a/static_core/assembler/CMakeLists.txt b/static_core/assembler/CMakeLists.txt index daabda06d..646f7d03a 100644 --- a/static_core/assembler/CMakeLists.txt +++ b/static_core/assembler/CMakeLists.txt @@ -91,6 +91,7 @@ include_directories(${CMAKE_BINARY_DIR}/libpandafile/include/) panda_add_library(arkassembler_static STATIC $) panda_target_link_libraries(arkassembler_static arkassembler_obj) +if(false) panda_add_gtest( NAME assembler_tests SOURCES @@ -106,6 +107,7 @@ panda_add_gtest( if(TARGET assembler_tests) panda_target_compile_options(assembler_tests PUBLIC "-Wno-ignored-attributes") endif() +endif() # if(false) panda_add_sanitizers(TARGET arkassembler_obj SANITIZERS ${PANDA_SANITIZERS_LIST}) panda_add_sanitizers(TARGET ark_asm SANITIZERS ${PANDA_SANITIZERS_LIST}) diff --git a/static_core/disassembler/CMakeLists.txt b/static_core/disassembler/CMakeLists.txt index 51966cc07..080a841d7 100644 --- a/static_core/disassembler/CMakeLists.txt +++ b/static_core/disassembler/CMakeLists.txt @@ -81,6 +81,7 @@ if(NOT PANDA_WITH_TESTS) return() endif() +if(false) # disasm_tests directory set(DISASM_TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) @@ -111,3 +112,4 @@ panda_add_gtest( SANITIZERS ${PANDA_SANITIZERS_LIST} ) +endif() # if(false) diff --git a/static_core/libpandabase/CMakeLists.txt b/static_core/libpandabase/CMakeLists.txt index fd0590711..409de2076 100644 --- a/static_core/libpandabase/CMakeLists.txt +++ b/static_core/libpandabase/CMakeLists.txt @@ -348,6 +348,7 @@ foreach(TARGET ${ARKBASE_TARGETS}) ) endforeach() +if(false) set(ARKBASE_TESTS_SOURCES tests/list_test.cpp tests/bit_helpers_test.cpp @@ -518,6 +519,7 @@ if(PANDA_TARGET_32) COMMAND ${PANDA_RUN_PREFIX} ${PANDA_BINARY_ROOT}/bin-gtests/memory_literals_test ) endif() +endif() # if(false) panda_gen_options(TARGET arkbase_obj YAML_FILE options.yaml GENERATED_HEADER base_options.h) diff --git a/static_core/libpandafile/CMakeLists.txt b/static_core/libpandafile/CMakeLists.txt index 6320f69db..5a9fd3670 100644 --- a/static_core/libpandafile/CMakeLists.txt +++ b/static_core/libpandafile/CMakeLists.txt @@ -91,8 +91,7 @@ add_dependencies(arkfile isa_gen_${PROJECT_NAME} type_gen_${PROJECT_NAME}) panda_target_link_libraries(arkfile ${LINK_LIBRARIES}) -# NOTE(aakmaev): Enable when #14728 internal issue will be fixed -if (NOT PANDA_TARGET_ARM64) +if (false) panda_add_gtest( NAME arkfile_tests SOURCES @@ -117,7 +116,7 @@ if (NOT PANDA_TARGET_ARM64) panda_target_include_directories(arkfile_tests PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include/tests) endif() -endif() +endif() # if(false) panda_add_sanitizers(TARGET arkfile SANITIZERS ${PANDA_SANITIZERS_LIST}) diff --git a/static_core/libziparchive/CMakeLists.txt b/static_core/libziparchive/CMakeLists.txt index a434764cc..7fa529dce 100644 --- a/static_core/libziparchive/CMakeLists.txt +++ b/static_core/libziparchive/CMakeLists.txt @@ -32,6 +32,7 @@ if(NOT PANDA_USE_PREBUILT_TARGETS) panda_target_link_libraries(arkziparchive zlib) endif() +if(false) panda_add_gtest( NAME arkziparchive_tests SOURCES @@ -44,5 +45,6 @@ panda_add_gtest( SANITIZERS ${PANDA_SANITIZERS_LIST} ) +endif() # if(false) panda_add_sanitizers(TARGET arkziparchive SANITIZERS ${PANDA_SANITIZERS_LIST}) diff --git a/static_core/plugins/ets/tests/ets_test_suite/gc/CMakeLists.txt b/static_core/plugins/ets/tests/ets_test_suite/gc/CMakeLists.txt index 00b03e90b..7ac5034d9 100644 --- a/static_core/plugins/ets/tests/ets_test_suite/gc/CMakeLists.txt +++ b/static_core/plugins/ets/tests/ets_test_suite/gc/CMakeLists.txt @@ -86,8 +86,7 @@ add_dependencies(mm_tests bouncing_pandas_ets-ets-jit bouncing_peas_ets-ets-int bouncing_peas_ets-ets-int-cpp - bouncing_peas_ets-ets-jit - etsnapi_test_suite) + bouncing_peas_ets-ets-jit) if(NOT CMAKE_CROSSCOMPILING) add_dependencies(mm_tests bouncing_pandas_ets-ets-aot diff --git a/static_core/plugins/ets/tests/micro-benchmarks/CMakeLists.txt b/static_core/plugins/ets/tests/micro-benchmarks/CMakeLists.txt index b8ef1806c..c1fd5be6d 100644 --- a/static_core/plugins/ets/tests/micro-benchmarks/CMakeLists.txt +++ b/static_core/plugins/ets/tests/micro-benchmarks/CMakeLists.txt @@ -75,5 +75,3 @@ if(PANDA_WITH_BENCHMARKS) endforeach() endforeach() endif() - -add_dependencies(ets_tests sampler_etsnapi_test_suite) diff --git a/static_core/plugins/ets/tests/napi/CMakeLists.txt b/static_core/plugins/ets/tests/napi/CMakeLists.txt index d375c3a9f..6b4dd5149 100644 --- a/static_core/plugins/ets/tests/napi/CMakeLists.txt +++ b/static_core/plugins/ets/tests/napi/CMakeLists.txt @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(false) add_subdirectory(bridges) add_subdirectory(etsnative) add_subdirectory(sampler) @@ -97,3 +98,4 @@ foreach(t ${ets_tests_list}) endforeach() add_dependencies(ets_tests etsnapi_test_suite) +endif() # if(false) diff --git a/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt b/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt index 032ec992b..7e04d6826 100644 --- a/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt +++ b/static_core/plugins/ets/tests/runtime/tooling/CMakeLists.txt @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(false) if (NOT TARGET es2panda OR PANDA_TARGET_ARM32) return() endif() @@ -45,3 +46,4 @@ add_custom_target(es2panda_convert_ets_debug_info DEPENDS es2panda_ets_stdlib_debug_info ) add_dependencies(debug_info_tests_ets_gtests es2panda_convert_ets_debug_info) +endif() # if(false) diff --git a/static_core/runtime/CMakeLists.txt b/static_core/runtime/CMakeLists.txt index 649f56f72..1ce098576 100644 --- a/static_core/runtime/CMakeLists.txt +++ b/static_core/runtime/CMakeLists.txt @@ -744,6 +744,7 @@ if (INTRUSIVE_TESTING) add_subdirectory(${PANDA_ROOT}/runtime/tests/intrusive-tests ${CMAKE_BINARY_DIR}/runtime/tests/intrusive_tests) endif() +if(false) function(add_multithread_gtests test_name) panda_add_gtest( NAME ${test_name} @@ -945,6 +946,7 @@ add_gtests( tests/regexp_test.cpp tests/dyn_buffer_test.cpp ) +endif() # if(false) # We run irtoc tests only in host mode, because irtoc tests are intended for testing only Irtoc language capabilities. if (PANDA_WITH_TESTS OR HOST_TOOLS) @@ -979,6 +981,7 @@ if (PANDA_WITH_TESTS OR HOST_TOOLS) endif() endif() +if(false) if (NOT PANDA_PRODUCT_BUILD) add_gtests( arkruntime_intrinsics_blacklist_test @@ -1064,6 +1067,7 @@ add_gtests( ${PANDA_ROOT}/compiler/tests/panda_runner.cpp $ ) +endif() # if(false) include(intrinsics.cmake) include(icu.cmake) diff --git a/static_core/static_linker/CMakeLists.txt b/static_core/static_linker/CMakeLists.txt index f57f7916a..973938343 100644 --- a/static_core/static_linker/CMakeLists.txt +++ b/static_core/static_linker/CMakeLists.txt @@ -65,6 +65,8 @@ panda_target_include_directories(ark_link PUBLIC include_directories(${PANDA_ROOT}/libpandabase/) include_directories(${CMAKE_BINARY_DIR}/libpandafile/include/) +if (false) if (PANDA_WITH_TESTS) add_subdirectory(tests) endif() +endif() # if(false) diff --git a/static_core/tests/CMakeLists.txt b/static_core/tests/CMakeLists.txt index 697a203d1..863d8052e 100644 --- a/static_core/tests/CMakeLists.txt +++ b/static_core/tests/CMakeLists.txt @@ -438,6 +438,7 @@ function(add_test_file) set(language_context "core") + if(false) if (ARG_VERIFIER_FAIL_TEST) set(VERIFIER_FAIL_TEST VERIFIER_FAIL_TEST) else() @@ -457,6 +458,7 @@ function(add_test_file) ) add_dependencies(${suite} ${target}-verifier) endif() + endif() # if(false) set(gc_types "stw" "gen-gc" "g1-gc") if (NOT PANDA_TARGET_ARM32) # Arm32 is not supported in the Irtoc @@ -1200,6 +1202,7 @@ add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/irtoc-op add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/irtoc-opcode-suite/throw.pa") if (TARGET verifier-tests) +if(false) # Verifier regression tests # Negative (must fail) add_verifier_test(FILE @@ -1270,6 +1273,7 @@ add_verifier_test(FILE "${CMAKE_CURRENT_SOURCE_DIR}/verifier-tests/bug_6434.pa" add_verifier_test(FILE "${CMAKE_CURRENT_SOURCE_DIR}/verifier-tests/initobj-bad-03.pa" VERIFIER_FAIL_TEST SEARCH_STDERR "Initobj calls not constructor") add_verifier_test(FILE "${CMAKE_CURRENT_SOURCE_DIR}/verifier-tests/access_field_nomodifier_core.pa") add_verifier_test(FILE "${CMAKE_CURRENT_SOURCE_DIR}/verifier-tests/exception_type.pa") +endif() # if(false) # Test for verification fail during runtime add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/verifier-tests/fail_in_runtime_ahead_of_time.pa" diff --git a/static_core/tests/cts-generator/CMakeLists.txt b/static_core/tests/cts-generator/CMakeLists.txt index aba30003c..755b8cc9e 100644 --- a/static_core/tests/cts-generator/CMakeLists.txt +++ b/static_core/tests/cts-generator/CMakeLists.txt @@ -85,12 +85,12 @@ if(NOT CMAKE_CROSSCOMPILING) if (NOT DEFINED CTS_TEST_SELECT_OPTION) if (CMAKE_BUILD_TYPE STREQUAL "Release") if (PANDA_ENABLE_UNDEFINED_BEHAVIOR_SANITIZER OR PANDA_ENABLE_ADDRESS_SANITIZER OR PANDA_ENABLE_THREAD_SANITIZER) - set(CTS_TEST_SELECT_OPTION "--exclude-tag sanitizer-fail") + set(CTS_TEST_SELECT_OPTION "--exclude-tag sanitizer-fail --exclude-tag verifier") else() - set(CTS_TEST_SELECT_OPTION "--exclude-tag release") + set(CTS_TEST_SELECT_OPTION "--exclude-tag release --exclude-tag verifier") endif() else() - set(CTS_TEST_SELECT_OPTION " ") + set(CTS_TEST_SELECT_OPTION "--exclude-tag verifier") endif() endif() @@ -98,12 +98,12 @@ if(NOT CMAKE_CROSSCOMPILING) if (NOT DEFINED CTS_TEST_SELECT_OPTION_JIT) if (CMAKE_BUILD_TYPE STREQUAL "Release") if (PANDA_ENABLE_UNDEFINED_BEHAVIOR_SANITIZER OR PANDA_ENABLE_ADDRESS_SANITIZER OR PANDA_ENABLE_THREAD_SANITIZER) - set(CTS_TEST_SELECT_OPTION_JIT "--exclude-tag sanitizer-fail") + set(CTS_TEST_SELECT_OPTION_JIT "--exclude-tag sanitizer-fail --exclude-tag verifier") else() - set(CTS_TEST_SELECT_OPTION_JIT "--exclude-tag release") + set(CTS_TEST_SELECT_OPTION_JIT "--exclude-tag release --exclude-tag verifier") endif() else() - set(CTS_TEST_SELECT_OPTION_JIT " ") + set(CTS_TEST_SELECT_OPTION_JIT "--exclude-tag verifier") endif() endif() diff --git a/static_core/tests/panda/CMakeLists.txt b/static_core/tests/panda/CMakeLists.txt index fbb6538c5..eb6563f18 100644 --- a/static_core/tests/panda/CMakeLists.txt +++ b/static_core/tests/panda/CMakeLists.txt @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +if(false) if (NOT PANDA_TARGET_MOBILE_WITH_MANAGED_LIBS) set(TEST_SOURCE_SUBDIR "sources") @@ -70,3 +71,4 @@ panda_add_gtest( add_dependencies(panda_cli_run_tests ark panda_cli_test_suites) endif() +endif() # if(false) diff --git a/static_core/verification/CMakeLists.txt b/static_core/verification/CMakeLists.txt index 888c027d8..69c4cd332 100644 --- a/static_core/verification/CMakeLists.txt +++ b/static_core/verification/CMakeLists.txt @@ -62,6 +62,7 @@ panda_gen( TEMPLATES verifier_messages_data_gen.cpp.erb ) +if(false) if ((PANDA_TARGET_X86 OR PANDA_TARGET_AMD64) AND PANDA_WITH_TESTS) panda_add_gtest( NO_CORES @@ -101,3 +102,4 @@ if ((PANDA_TARGET_X86 OR PANDA_TARGET_AMD64) AND PANDA_WITH_TESTS) panda_add_sanitizers(TARGET pandaverification_rapidcheck_gtest_tests SANITIZERS ${PANDA_SANITIZERS_LIST}) endif() endif() +endif() # if(false) -- Gitee From 113ceb210b1b27a650c8103eb6567b6e7d7027a9 Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Mon, 11 Nov 2024 11:56:33 +0300 Subject: [PATCH 25/36] [huge] Introduce more tests Signed-off-by: Denis Zavedeev --- static_core/tests/CMakeLists.txt | 64 ++ static_core/tests/checked/CMakeLists.txt | 9 + static_core/tests/checked/aot.pa | 19 + static_core/tests/checked/cast_bool.pa | 10 +- .../checked/checkcast_elimination_test.pa | 37 + static_core/tests/checked/const_array_test.pa | 22 +- static_core/tests/checked/cross_peephole.pa | 6 +- .../tests/checked/disasm_and_log_demo.pa | 4 + .../checked/external_call/external-call-01.pa | 49 + .../checked/external_call/external-call-02.pa | 25 + .../tests/checked/external_inline/a.pa | 28 + .../tests/checked/external_inline/b.pa | 25 + static_core/tests/checked/float_zero.pa | 25 + .../tests/checked/implicit_nullcheck_tests.pa | 4 - .../tests/checked/irreducible_loop_test.pa | 9 +- .../checked/isinstance_elimination_test.pa | 13 +- static_core/tests/checked/ldarray_obj.pa | 8 + .../tests/checked/llvmaot-gc-intrusion.pa | 25 + static_core/tests/checked/monitor.pa | 47 + static_core/tests/checked/parameter_test.pa | 10 +- .../tests/checked/ref_check_elim_test.pa | 53 +- static_core/tests/checked/stack_overflow.pa | 20 +- static_core/tests/checked/tlab_test.pa | 23 + .../verify_aot_tests/verify_aot_test.pa | 5 +- static_core/tests/checked/wrb-arr.pa | 45 + static_core/tests/checked/wrb-obj.pa | 42 + .../tests/checked/zero_const_in_save_state.pa | 18 +- static_core/tests/cts-assembly/abs-f64-01.pa | 31 + static_core/tests/cts-assembly/abs-f64-02.pa | 31 + static_core/tests/cts-assembly/abs-i32-i64.pa | 30 + .../tests/cts-assembly/arrays-checkcast.pa | 90 ++ .../tests/cts-assembly/arrays-isinstance.pa | 41 + .../tests/cts-assembly/call-static-01.pa | 30 + .../tests/cts-assembly/call-static-02.pa | 25 + .../tests/cts-assembly/call-static-03.pa | 26 + .../tests/cts-assembly/call-static-04.pa | 26 + .../tests/cts-assembly/call-virtual-01.pa | 44 + static_core/tests/cts-assembly/cmp-u32-01.pa | 27 + static_core/tests/cts-assembly/cmp-u64-01.pa | 27 + .../tests/cts-assembly/const-f32-01.pa | 18 + .../tests/cts-assembly/const-f64-01.pa | 18 + .../tests/cts-assembly/const-f64-02.pa | 26 + .../tests/cts-assembly/const-f64-03.pa | 39 + .../tests/cts-assembly/const-f64-04.pa | 919 ++++++++++++++++++ .../tests/cts-assembly/floatcast-test-1.pa | 207 ++++ .../tests/cts-assembly/floatcast-test-2.pa | 1 + .../tests/cts-assembly/llvm-options.pa | 17 + .../tests/cts-assembly/load-and-init-01.pa | 32 + .../tests/cts-assembly/load-and-init-02.pa | 41 + static_core/tests/cts-assembly/long-array.pa | 38 + .../tests/cts-assembly/math-fadd-01.pa | 30 + .../tests/cts-assembly/math-fdiv-01.pa | 27 + .../tests/cts-assembly/math-fmod-01.pa | 27 + .../tests/cts-assembly/math-fmul-01.pa | 29 + .../tests/cts-assembly/math-fneg-01.pa | 26 + .../tests/cts-assembly/math-fneg-02.pa | 26 + .../tests/cts-assembly/math-fsub-01.pa | 30 + static_core/tests/cts-assembly/math-udiv.pa | 30 + static_core/tests/cts-assembly/math-urem.pa | 33 + static_core/tests/cts-assembly/min-max-int.pa | 54 + static_core/tests/cts-assembly/no-inline-0.pa | 25 + static_core/tests/cts-assembly/no-inline-1.pa | 25 + static_core/tests/cts-assembly/no-inline-2.pa | 1 + static_core/tests/cts-assembly/no-inline-3.pa | 1 + static_core/tests/cts-assembly/obj-arr.pa | 158 +++ .../cts-assembly/obj-checkcast-normal-bug.pa | 47 + static_core/tests/cts-assembly/obj-null-01.pa | 46 + static_core/tests/cts-assembly/obj-null-02.pa | 48 + static_core/tests/cts-assembly/obj-null-03.pa | 53 + static_core/tests/cts-assembly/obj-null-04.pa | 49 + static_core/tests/cts-assembly/obj-null-05.pa | 49 + static_core/tests/cts-assembly/obj-null-06.pa | 50 + static_core/tests/cts-assembly/phi-f64-01.pa | 22 + static_core/tests/cts-assembly/shl31.pa | 71 ++ static_core/tests/cts-assembly/sinf64.pa | 33 + .../tests/cts-assembly/small-fields-01.pa | 53 + .../tests/cts-assembly/small-fields-02.pa | 41 + .../cts-assembly/small-static-fields-01.pa | 38 + .../cts-assembly/small-static-fields-02.pa | 35 + static_core/tests/cts-assembly/test-max.pa | 88 ++ static_core/tests/cts-assembly/test-min.pa | 88 ++ .../tests/cts-assembly/type-coercion-01.pa | 33 + .../tests/cts-assembly/type-coercion-02.pa | 51 + .../tests/cts-assembly/type-coercion-03.pa | 43 + .../tests/cts-assembly/type-coercion-04.pa | 64 ++ .../tests/cts-assembly/type-coercion-05.pa | 43 + .../irtoc-interpreter-tests/array-npe-1.pa | 34 + .../irtoc-interpreter-tests/array-npe-2.pa | 39 + .../irtoc-interpreter-tests/array-oob-1.pa | 35 + .../irtoc-interpreter-tests/array-oob-2.pa | 40 + static_core/tests/regression/fmodf.pa | 54 + 91 files changed, 4173 insertions(+), 25 deletions(-) create mode 100644 static_core/tests/checked/external_call/external-call-01.pa create mode 100644 static_core/tests/checked/external_call/external-call-02.pa create mode 100644 static_core/tests/checked/external_inline/a.pa create mode 100644 static_core/tests/checked/external_inline/b.pa create mode 100644 static_core/tests/checked/llvmaot-gc-intrusion.pa create mode 100644 static_core/tests/checked/wrb-arr.pa create mode 100644 static_core/tests/checked/wrb-obj.pa create mode 100644 static_core/tests/cts-assembly/abs-f64-01.pa create mode 100644 static_core/tests/cts-assembly/abs-f64-02.pa create mode 100644 static_core/tests/cts-assembly/abs-i32-i64.pa create mode 100644 static_core/tests/cts-assembly/arrays-checkcast.pa create mode 100644 static_core/tests/cts-assembly/arrays-isinstance.pa create mode 100644 static_core/tests/cts-assembly/call-static-01.pa create mode 100644 static_core/tests/cts-assembly/call-static-02.pa create mode 100644 static_core/tests/cts-assembly/call-static-03.pa create mode 100644 static_core/tests/cts-assembly/call-static-04.pa create mode 100644 static_core/tests/cts-assembly/call-virtual-01.pa create mode 100644 static_core/tests/cts-assembly/cmp-u32-01.pa create mode 100644 static_core/tests/cts-assembly/cmp-u64-01.pa create mode 100644 static_core/tests/cts-assembly/const-f32-01.pa create mode 100644 static_core/tests/cts-assembly/const-f64-01.pa create mode 100644 static_core/tests/cts-assembly/const-f64-02.pa create mode 100644 static_core/tests/cts-assembly/const-f64-03.pa create mode 100644 static_core/tests/cts-assembly/const-f64-04.pa create mode 100644 static_core/tests/cts-assembly/floatcast-test-1.pa create mode 120000 static_core/tests/cts-assembly/floatcast-test-2.pa create mode 100644 static_core/tests/cts-assembly/llvm-options.pa create mode 100644 static_core/tests/cts-assembly/load-and-init-01.pa create mode 100644 static_core/tests/cts-assembly/load-and-init-02.pa create mode 100644 static_core/tests/cts-assembly/long-array.pa create mode 100644 static_core/tests/cts-assembly/math-fadd-01.pa create mode 100644 static_core/tests/cts-assembly/math-fdiv-01.pa create mode 100644 static_core/tests/cts-assembly/math-fmod-01.pa create mode 100644 static_core/tests/cts-assembly/math-fmul-01.pa create mode 100644 static_core/tests/cts-assembly/math-fneg-01.pa create mode 100644 static_core/tests/cts-assembly/math-fneg-02.pa create mode 100644 static_core/tests/cts-assembly/math-fsub-01.pa create mode 100644 static_core/tests/cts-assembly/math-udiv.pa create mode 100644 static_core/tests/cts-assembly/math-urem.pa create mode 100644 static_core/tests/cts-assembly/min-max-int.pa create mode 100644 static_core/tests/cts-assembly/no-inline-0.pa create mode 100644 static_core/tests/cts-assembly/no-inline-1.pa create mode 120000 static_core/tests/cts-assembly/no-inline-2.pa create mode 120000 static_core/tests/cts-assembly/no-inline-3.pa create mode 100644 static_core/tests/cts-assembly/obj-arr.pa create mode 100644 static_core/tests/cts-assembly/obj-checkcast-normal-bug.pa create mode 100644 static_core/tests/cts-assembly/obj-null-01.pa create mode 100644 static_core/tests/cts-assembly/obj-null-02.pa create mode 100644 static_core/tests/cts-assembly/obj-null-03.pa create mode 100644 static_core/tests/cts-assembly/obj-null-04.pa create mode 100644 static_core/tests/cts-assembly/obj-null-05.pa create mode 100644 static_core/tests/cts-assembly/obj-null-06.pa create mode 100644 static_core/tests/cts-assembly/phi-f64-01.pa create mode 100644 static_core/tests/cts-assembly/shl31.pa create mode 100644 static_core/tests/cts-assembly/sinf64.pa create mode 100644 static_core/tests/cts-assembly/small-fields-01.pa create mode 100644 static_core/tests/cts-assembly/small-fields-02.pa create mode 100644 static_core/tests/cts-assembly/small-static-fields-01.pa create mode 100644 static_core/tests/cts-assembly/small-static-fields-02.pa create mode 100644 static_core/tests/cts-assembly/test-max.pa create mode 100644 static_core/tests/cts-assembly/test-min.pa create mode 100644 static_core/tests/cts-assembly/type-coercion-01.pa create mode 100644 static_core/tests/cts-assembly/type-coercion-02.pa create mode 100644 static_core/tests/cts-assembly/type-coercion-03.pa create mode 100644 static_core/tests/cts-assembly/type-coercion-04.pa create mode 100644 static_core/tests/cts-assembly/type-coercion-05.pa create mode 100644 static_core/tests/irtoc-interpreter-tests/array-npe-1.pa create mode 100644 static_core/tests/irtoc-interpreter-tests/array-npe-2.pa create mode 100644 static_core/tests/irtoc-interpreter-tests/array-oob-1.pa create mode 100644 static_core/tests/irtoc-interpreter-tests/array-oob-2.pa create mode 100644 static_core/tests/regression/fmodf.pa diff --git a/static_core/tests/CMakeLists.txt b/static_core/tests/CMakeLists.txt index 863d8052e..20f76cfa7 100644 --- a/static_core/tests/CMakeLists.txt +++ b/static_core/tests/CMakeLists.txt @@ -1107,22 +1107,82 @@ add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/tst-branch.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/tst-compare.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/tst-select.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/abs-f64-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/abs-f64-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/abs-i32-i64.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/call-static-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/call-static-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/call-static-03.pa" LLVMAOT_OPTIONS --llvm-dump-after AOT_DEBUG_LOG_MESSAGE "call.*statepoint.*_GLOBAL::test") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/call-static-04.pa" LLVMAOT_OPTIONS --llvm-dump-after AOT_DEBUG_LOG_MESSAGE "call.*statepoint.*_GLOBAL::test") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/call-virtual-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/const-f32-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/const-f64-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/const-f64-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/const-f64-03.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/const-f64-04.pa" EXPECTED_STDOUT "43.8451") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/cmp-u32-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/cmp-u64-01.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/intrinsic-f32-01.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/intrinsic-f32-02.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/intrinsic-f32-03.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/intrinsic-f32-04.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/intrinsic-f32-05.pa" EXPECTED_STDOUT "0.785398") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/load-and-init-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/load-and-init-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-fadd-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-fdiv-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-fmod-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-fmul-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-fneg-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-fneg-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-fsub-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-udiv.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/math-urem.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/phi-f64-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-arr.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-checkcast-normal-bug.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-null-01.pa" COMPILER_OPTIONS --compiler-regex=.*store_42) +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-null-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-null-03.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-null-04.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-null-05.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/obj-null-06.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/shl31.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/sinf64.pa" LLVMAOT_OPTIONS --compiler-non-optimizing=true) +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/test-max.pa" SKIP_VERIFICATION) +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/test-min.pa" SKIP_VERIFICATION) +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/min-max-int.pa" SKIP_VERIFICATION) add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/floatcast-test-0.pa" SKIP_VERIFICATION) +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/floatcast-test-1.pa" SKIP_VERIFICATION) +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/floatcast-test-2.pa" COMPILER_OPTIONS --compiler-inlining=false SKIP_VERIFICATION) add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/try-catch-01.pa" SKIP_VERIFICATION) add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/try-catch-02.pa" SKIP_VERIFICATION) add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/try-catch-03.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/try-catch-04.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/type-coercion-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/type-coercion-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/type-coercion-03.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/type-coercion-04.pa" EXPECTED_STDOUT "11111") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/type-coercion-05.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/small-fields-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/small-fields-02.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/small-static-fields-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/small-static-fields-02.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/rodatas-01.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/long-array.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/llvm-options.pa" LLVMAOT_OPTIONS --compiler-non-optimizing=true --llvm-options="--print-after-isel" AOT_DEBUG_LOG_MESSAGE "Machine code for function u1 _GLOBAL::main") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/arrays-isinstance.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/arrays-checkcast.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/no-inline-0.pa" LLVMAOT_OPTIONS --llvm-dump-after AOT_DEBUG_LOG_MESSAGE "call.*statepoint.*_GLOBAL::test") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/no-inline-1.pa" COMPILER_OPTIONS --compiler-inlining-blacklist=_GLOBAL::test LLVMAOT_OPTIONS --llvm-dump-after AOT_DEBUG_LOG_MESSAGE "call.*statepoint.*_GLOBAL::test") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/no-inline-2.pa" COMPILER_OPTIONS --compiler-inlining=false LLVMAOT_OPTIONS --llvm-dump-after AOT_DEBUG_LOG_MESSAGE "call.*statepoint.*_GLOBAL::test") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/cts-assembly/no-inline-3.pa" LLVMAOT_OPTIONS --llvm-pre-opt=0 --llvm-inlining=false --llvm-dump-after AOT_DEBUG_LOG_MESSAGE "call.*statepoint.*_GLOBAL::test") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/allocate-252-params.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/bitops-bitwise-and.pa" COMPILER_OPTIONS --compiler-print-stats) add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/math-partial-sums.pa" COMPILER_OPTIONS --compiler-print-stats DISABLE_LIMIT_STD_ALLOC) add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/fmod.pa" COMPILER_OPTIONS --compiler-inlining=false) +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/fmodf.pa" COMPILER_OPTIONS --compiler-inlining=false) add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/stack-4-params.pa" COMPILER_OPTIONS --compiler-inlining=false VERIFIER_FAIL_TEST SEARCH_STDERR "Bad register type") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/stack-9-params.pa" COMPILER_OPTIONS --compiler-inlining=false VERIFIER_FAIL_TEST SEARCH_STDERR "Bad register type") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/regression/fcmp.pa" VERIFIER_FAIL_TEST SEARCH_STDERR "Bad register type") @@ -1153,6 +1213,10 @@ add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/multiarr # Lots of runtime calls with enabled '--verify-entrypoints' option cause lots of standard allocations add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/barriers.pa" DISABLE_LIMIT_STD_ALLOC SKIP_CROSS "arm32" G1_GC_SIZE_LIMITS "--heap-size-limit=4718592 --young-space-size=324288") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/array-npe-1.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/array-npe-2.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/array-oob-1.pa") +add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/array-oob-2.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/irtoc-opcode-suite/ldai.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/irtoc-opcode-suite/and.pa") add_test_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/irtoc-interpreter-tests/irtoc-opcode-suite/andi.pa") diff --git a/static_core/tests/checked/CMakeLists.txt b/static_core/tests/checked/CMakeLists.txt index 280b1e509..2a98fb8fa 100644 --- a/static_core/tests/checked/CMakeLists.txt +++ b/static_core/tests/checked/CMakeLists.txt @@ -178,15 +178,24 @@ if (PANDA_TARGET_AMD64 OR (PANDA_TARGET_ARM64 AND NOT PANDA_ENABLE_ADDRESS_SANIT panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/memory-coalescing.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/memory-coalescing1.pa) if (PANDA_LLVM_AOT) + panda_add_checked_test(NAME external_inline + FILE ${CMAKE_CURRENT_SOURCE_DIR}/external_inline/a.pa + EXT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/external_inline/b.pa) + panda_add_checked_test(NAME external_call + FILE ${CMAKE_CURRENT_SOURCE_DIR}/external_call/external-call-01.pa + EXT_FILES ${CMAKE_CURRENT_SOURCE_DIR}/external_call/external-call-02.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/virtual_to_static.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/memset.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-optlevel.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-broken-ir.pa) + panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-gc-intrusion.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-gc-liveness.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-tracking.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-inlines-from-split-module.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-gc-int-vs-ptr.pa) + panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/wrb-arr.pa) + panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/wrb-obj.pa) if (PANDA_TARGET_AMD64) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/fill-const-array/fill-const-array-513.pa) endif() diff --git a/static_core/tests/checked/aot.pa b/static_core/tests/checked/aot.pa index 25052085d..19f8295ea 100644 --- a/static_core/tests/checked/aot.pa +++ b/static_core/tests/checked/aot.pa @@ -20,6 +20,15 @@ #! EVENT "AotEntrypointFound,_GLOBAL::func2" #! EVENT "AotEntrypointFound,_GLOBAL::func3" +#! CHECKER All methods found - LLVM +#! RUN_LLVM options: "--compiler-inlining false" +#! RUN options: "", entry: "_GLOBAL::main", result: 52 +#! EVENT_NOT /Inline.*/ +#! EVENT "AotEntrypointFound,_GLOBAL::func1" +#! EVENT "AotEntrypointFound,_GLOBAL::func2" +#! EVENT "AotEntrypointFound,_GLOBAL::func3" + + #! CHECKER Various methods compiled #! RUN_PAOC options: "--compiler-inlining false --compiler-regex '(_GLOBAL::func[13]|Test::f[23])'" #! RUN options: "", entry: "_GLOBAL::main2", result: 58 @@ -30,6 +39,16 @@ #! EVENT "AotEntrypointFound,Test::f3" #! EVENT_NOT "AotEntrypointFound,Test::f1" +#! CHECKER Various methods compiled - LLVM +#! RUN_LLVM options: "--compiler-inlining false --compiler-regex '(_GLOBAL::func[13]|Test::f[23])'" +#! RUN options: "", entry: "_GLOBAL::main2", result: 58 +#! EVENT "AotEntrypointFound,_GLOBAL::func1" +#! EVENT "AotEntrypointFound,_GLOBAL::func3" +#! EVENT_NOT "AotEntrypointFound,_GLOBAL::func2" +#! EVENT "AotEntrypointFound,Test::f2" +#! EVENT "AotEntrypointFound,Test::f3" +#! EVENT_NOT "AotEntrypointFound,Test::f1" + .record Test {} .function i32 Test.f1() { diff --git a/static_core/tests/checked/cast_bool.pa b/static_core/tests/checked/cast_bool.pa index 0aced8b7e..ae88cd9a3 100644 --- a/static_core/tests/checked/cast_bool.pa +++ b/static_core/tests/checked/cast_bool.pa @@ -12,9 +12,17 @@ # limitations under the License. #! CHECKER Check that cast in bool work for all arch -#! RUN force_jit: true, options: "", entry: "_GLOBAL::main_all", result: 0 +#! RUN force_jit: true, options: "", entry: "_GLOBAL::main_all" #! EVENT /Compilation,_GLOBAL::main_all,.*COMPILED/ +#! CHECKER Check that cast in bool work for all arch at Regular AOT +#! RUN_PAOC options: "" +#! RUN entry: "_GLOBAL::main_all" + +#! CHECKER Check that cast in bool work for all arch at LLVM AOT +#! RUN_LLVM options: "" +#! RUN entry: "_GLOBAL::main_all" + .function u1 main_all() { movi v2, 0xF1F1 call __noinline__cast_i32, v2 diff --git a/static_core/tests/checked/checkcast_elimination_test.pa b/static_core/tests/checked/checkcast_elimination_test.pa index be327d6c0..77408fadd 100644 --- a/static_core/tests/checked/checkcast_elimination_test.pa +++ b/static_core/tests/checked/checkcast_elimination_test.pa @@ -24,6 +24,22 @@ #! INST_NOT "CheckCast" #! INST "Deoptimize" +#! CHECKER CheckCast Elimination applied, replaced on deoptimize at Regular AOT. +#! RUN_PAOC options: "--compiler-regex=_GLOBAL.*" +#! METHOD "_GLOBAL::main1" +#! PASS_AFTER "Inline" +#! INST_NOT "CheckCast" +#! INST "Deoptimize" +#! RUN entry: "_GLOBAL::main1" + +#! CHECKER CheckCast Elimination applied, replaced on deoptimize at LLVM AOT. +#! RUN_LLVM options: "--compiler-regex=_GLOBAL.*" +#! METHOD "_GLOBAL::main1" +#! PASS_AFTER "Inline" +#! INST_NOT "CheckCast" +#! INST "Deoptimize" +#! RUN entry: "_GLOBAL::main1" + .function u1 main1() { newobj v0, A lda.obj v0 @@ -52,6 +68,20 @@ catch_block2_begin: #! PASS_AFTER "Inline" #! INST_NOT "CheckCast" +#! CHECKER CheckCast Elimination applied, remove redundant checkcast at Regular AOT. +#! RUN_PAOC options: "--compiler-regex=_GLOBAL.*" +#! METHOD "_GLOBAL::main2" +#! PASS_AFTER "Inline" +#! INST_NOT "CheckCast" +#! RUN entry: "_GLOBAL::main2" + +#! CHECKER CheckCast Elimination applied, remove redundant checkcast at LLVM AOT. +#! RUN_LLVM options: "--compiler-regex=_GLOBAL.*" +#! METHOD "_GLOBAL::main2" +#! PASS_AFTER "Inline" +#! INST_NOT "CheckCast" +#! RUN entry: "_GLOBAL::main2" + .function u1 main2() { newobj v0, B lda.obj v0 @@ -79,6 +109,13 @@ catch_block2_begin: #! CHECKER CheckCast Elimination applied, remove redundant checkcast, inline. #! RUN force_jit: true, options: "--compiler-regex=_GLOBAL.*", entry: "_GLOBAL::main3" +#! CHECKER CheckCast Elimination applied, remove redundant checkcast, Inline at Regular AOT. +#! RUN_PAOC options: "--compiler-regex=_GLOBAL.*" +#! RUN entry: "_GLOBAL::main3" + +#! CHECKER CheckCast Elimination applied, remove redundant checkcast, Inline at LLVM AOT. +#! RUN_LLVM options: "--compiler-regex=_GLOBAL.*" +#! RUN entry: "_GLOBAL::main3" .function i32 test1() { newobj v0, B lda.obj v0 diff --git a/static_core/tests/checked/const_array_test.pa b/static_core/tests/checked/const_array_test.pa index c7ab25c9e..fb703d748 100644 --- a/static_core/tests/checked/const_array_test.pa +++ b/static_core/tests/checked/const_array_test.pa @@ -16,7 +16,7 @@ # #! CHECKER Split ConstArray -#! RUN force_jit: true, options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=2", entry: "_GLOBAL::main" +#! RUN force_jit: true, options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=2", entry: "_GLOBAL::main" #! EVENT /Compilation,.*main.*/ #! METHOD "_GLOBAL::main" #! PASS_AFTER "IrBuilder" @@ -25,8 +25,16 @@ #! INST_NEXT "FillConstArray" #! INST_NOT "StoreArray" +#! CHECKER Split ConstArray AOT +#! RUN_PAOC options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=2" +#! RUN entry: "_GLOBAL::main" + +#! CHECKER Split ConstArray LLVM +#! RUN_LLVM options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=2" +#! RUN entry: "_GLOBAL::main" + #! CHECKER Fill ConstArray -#! RUN force_jit: true, options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=4", entry: "_GLOBAL::main" +#! RUN force_jit: true, options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=4", entry: "_GLOBAL::main" #! EVENT /Compilation,.*main.*/ #! METHOD "_GLOBAL::main" #! PASS_AFTER "IrBuilder" @@ -35,12 +43,12 @@ #! INST_NOT "FillConstArray" #! INST_NOT "LoadConstArray" -#! CHECKER Split ConstArray AOT -#! RUN_PAOC options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=2" +#! CHECKER Fill ConstArray AOT +#! RUN_PAOC options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=4" #! RUN entry: "_GLOBAL::main" -#! CHECKER Fill ConstArray AOT -#! RUN_PAOC options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=4" +#! CHECKER Fill ConstArray LLVM +#! RUN_LLVM options: "--compiler-regex=_GLOBAL::main --compiler-unfold-const-array-max-size=4" #! RUN entry: "_GLOBAL::main" .record panda.String @@ -150,4 +158,4 @@ loop_error_9: label: lda a0 return -} \ No newline at end of file +} diff --git a/static_core/tests/checked/cross_peephole.pa b/static_core/tests/checked/cross_peephole.pa index 897d49c5c..c1fc6d265 100644 --- a/static_core/tests/checked/cross_peephole.pa +++ b/static_core/tests/checked/cross_peephole.pa @@ -25,6 +25,10 @@ #! RUN_PAOC options: "--compiler-cross-arch=arm" #! RUN_PAOC options: "--compiler-cross-arch=arm64" +#! CHECKER Compiling a method arm/arm64 on amd64 in LLVM AOT +#! SKIP_IF @architecture != "x64" +#! RUN_LLVM options: "--compiler-cross-arch=arm64" + # Check, that need second peephole for lowering @@ -41,7 +45,7 @@ #! CHECKER Check that lowering is applied for Return in AOT #! SKIP_IF @architecture == "arm32" -#! RUN_PAOC options:"" +#! RUN_PAOC options: "" #! METHOD "_GLOBAL::main" #! PASS_AFTER "DeoptimizeElimination" #! INST "Return " diff --git a/static_core/tests/checked/disasm_and_log_demo.pa b/static_core/tests/checked/disasm_and_log_demo.pa index 9be9bbf80..1fcf9ab16 100644 --- a/static_core/tests/checked/disasm_and_log_demo.pa +++ b/static_core/tests/checked/disasm_and_log_demo.pa @@ -15,6 +15,10 @@ #! RUN force_jit: true, options: "--compiler-disasm-dump", entry: "_GLOBAL::main" #! EVENT /Compilation,_GLOBAL::main,.*COMPILED/ +#! CHECKER Check that MmapMemPool: Try to free arena Regular AOT +#! RUN_PAOC options: "--compiler-disasm-dump" +#! RUN entry: "_GLOBAL::main" + .function u1 main (){ ldai 0 return diff --git a/static_core/tests/checked/external_call/external-call-01.pa b/static_core/tests/checked/external_call/external-call-01.pa new file mode 100644 index 000000000..f141b38fa --- /dev/null +++ b/static_core/tests/checked/external_call/external-call-01.pa @@ -0,0 +1,49 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#! CHECKER External call Regular AOT +#! RUN_PAOC options: "--paoc-panda-files=../external-call-02.bin" +#! RUN options: "", entry: "_GLOBAL::main" + +#! CHECKER External call LLVM AOT +#! RUN_LLVM options: "--compiler-non-optimizing=true --paoc-panda-files=../external-call-02.bin" +#! RUN options: "", entry: "_GLOBAL::main" + +.record Functional { +} + +.function i32 Functional.identity(i32 a0) { + lda a0 + return +} + +.record B +.function i32 B.foo() + +.function i32 main() { + movi v0, 44 + call.short B.foo + jne v0, failure_b_foo_call + call.short Functional.identity, v0 + jne v0, failure_identity_call + + ldai 0 + return +failure_identity_call: + ldai 1 + return + +failure_b_foo_call: + ldai 2 + return +} diff --git a/static_core/tests/checked/external_call/external-call-02.pa b/static_core/tests/checked/external_call/external-call-02.pa new file mode 100644 index 000000000..7a0fb655d --- /dev/null +++ b/static_core/tests/checked/external_call/external-call-02.pa @@ -0,0 +1,25 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Functional + +.function i32 Functional.identity(i32 a0) + +.record B { +} + +.function i32 B.foo() { + movi v0, 44 + call.short Functional.identity, v0 + return +} diff --git a/static_core/tests/checked/external_inline/a.pa b/static_core/tests/checked/external_inline/a.pa new file mode 100644 index 000000000..7404d6858 --- /dev/null +++ b/static_core/tests/checked/external_inline/a.pa @@ -0,0 +1,28 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#! CHECKER External Inline +#! RUN_PAOC options: "--paoc-panda-files ../b.bin" +#! RUN options: "", entry: "_GLOBAL::main", result: 10 + +#! CHECKER External Inline LLVM +#! RUN_LLVM options: "--paoc-panda-files ../b.bin" +#! RUN options: "", entry: "_GLOBAL::main", result: 10 + +.record InlineTestExt +.function i32 InlineTestExt.small_func() + +.function i32 main() { + call.short InlineTestExt.small_func + return +} diff --git a/static_core/tests/checked/external_inline/b.pa b/static_core/tests/checked/external_inline/b.pa new file mode 100644 index 000000000..38fde3814 --- /dev/null +++ b/static_core/tests/checked/external_inline/b.pa @@ -0,0 +1,25 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record InlineTestExt <> {} +.record Foo { + i32 f +} + +.function i32 InlineTestExt.small_func() { + newobj v0, Foo + ldai 10 + stobj v0, Foo.f + ldobj v0, Foo.f + return +} diff --git a/static_core/tests/checked/float_zero.pa b/static_core/tests/checked/float_zero.pa index 275495436..f5fa13250 100644 --- a/static_core/tests/checked/float_zero.pa +++ b/static_core/tests/checked/float_zero.pa @@ -24,6 +24,31 @@ #! INST_NOT "Constant" #! INST_NOT "Return " +#! CHECKER Check float zero Regular AOT +#! RUN_PAOC options: "" +#! METHOD "_GLOBAL::__noinline__call_foo" +#! PASS_AFTER "IrBuilder" +#! INST "Constant" +#! INST "Return" +#! INST_NOT "ReturnI" +#! PASS_AFTER "Codegen" +#! INST "ReturnI" +#! INST_NOT "Constant" +#! INST_NOT "Return " +#! RUN entry: "_GLOBAL::main" + +#! CHECKER Check float zero LLVM AOT +#! RUN_LLVM options: "--llvm-dump-before" +#! READ_FILE "console.out" +#! INST /define weak protected.*GLOBAL::__noinline__call_foo/ +#! INST_NEXT "ret double 0.0" +#! METHOD "_GLOBAL::__noinline__call_foo" +#! PASS_AFTER "IrBuilder" +#! INST "Constant" +#! INST "Return" +#! INST_NOT "ReturnI" +#! RUN entry: "_GLOBAL::main" + .function f64 __noinline__call_foo(f64 a0) { fldai.64 0.0 return.64 diff --git a/static_core/tests/checked/implicit_nullcheck_tests.pa b/static_core/tests/checked/implicit_nullcheck_tests.pa index a9a749ea9..2f83c429f 100644 --- a/static_core/tests/checked/implicit_nullcheck_tests.pa +++ b/static_core/tests/checked/implicit_nullcheck_tests.pa @@ -34,10 +34,6 @@ #! CHECKER Use implicit NullCheck for array and object in AOT #! SKIP_IF @architecture == "arm32" #! RUN_PAOC options: "" -#! EVENT /Compilation,.*__noinline__call_ldarray.*/ -#! EVENT /Compilation,.*__noinline__call_starray.*/ -#! EVENT /Compilation,.*__noinline__call_ldobj_i32.*/ -#! EVENT /Compilation,.*__noinline__call_stobj_i32.*/ #! RUN options: "", entry: "_GLOBAL::main" #! EVENT /ImplicitNullcheck,.*/ #! EVENT_NEXT /Exception,.*__noinline__call_ldarray.*NULL_CHECK/ diff --git a/static_core/tests/checked/irreducible_loop_test.pa b/static_core/tests/checked/irreducible_loop_test.pa index 3bbbfea85..82ff336dc 100644 --- a/static_core/tests/checked/irreducible_loop_test.pa +++ b/static_core/tests/checked/irreducible_loop_test.pa @@ -11,12 +11,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -#! CHECKER Irreduceble loop test +#! CHECKER Irreducible loop test #! RUN_PAOC options: "--compiler-regex=.*try_to_reproduce.*" #! RUN options: "", entry: "_GLOBAL::main", result: 1 #! EVENT /AotEntrypointFound,_GLOBAL::try_to_reproduce/ -#! CHECKER Irreduceble loop test with reg maps on safepoints +#! CHECKER Irreducible loop test LLVM AOT +#! RUN_LLVM options: "--compiler-regex=.*try_to_reproduce.*" +#! RUN options: "", entry: "_GLOBAL::main", result: 1 +#! EVENT /AotEntrypointFound,_GLOBAL::try_to_reproduce/ + +#! CHECKER Irreducible loop test with reg maps on safepoints #! RUN_PAOC options: "--compiler-regex=.*try_to_reproduce.* --compiler-safe-points-require-reg-map=true" #! RUN options: "", entry: "_GLOBAL::main", result: 1 #! EVENT /AotEntrypointFound,_GLOBAL::try_to_reproduce/ diff --git a/static_core/tests/checked/isinstance_elimination_test.pa b/static_core/tests/checked/isinstance_elimination_test.pa index 4bab2db44..c6ce8ebbb 100644 --- a/static_core/tests/checked/isinstance_elimination_test.pa +++ b/static_core/tests/checked/isinstance_elimination_test.pa @@ -17,6 +17,17 @@ #! PASS_AFTER "TryCatchResolving" #! INST_NOT "IsInstance" +#! CHECKER IsInstance Elimination applied at Regular AOT. +#! RUN_PAOC options: "--compiler-regex=_GLOBAL.*" +#! METHOD "_GLOBAL::main" +#! PASS_AFTER "Cleanup" +#! INST_NOT "IsInstance" +#! RUN entry: "_GLOBAL::main" + +#! CHECKER IsInstance Elimination applied at LLVM AOT. +#! RUN_LLVM options: "--compiler-regex=_GLOBAL.*" +#! RUN entry: "_GLOBAL::main" + .record A1 {} .record B1 {} .record C1 {} @@ -41,4 +52,4 @@ exit_failure: ldai 1 return -} \ No newline at end of file +} diff --git a/static_core/tests/checked/ldarray_obj.pa b/static_core/tests/checked/ldarray_obj.pa index acf34303e..c7be88e13 100644 --- a/static_core/tests/checked/ldarray_obj.pa +++ b/static_core/tests/checked/ldarray_obj.pa @@ -16,6 +16,14 @@ #! EVENT /Compilation,_GLOBAL::test,.*COMPILED/ #! METHOD "_GLOBAL::test" +#! CHECKER Regular AOT rewrite index value +#! RUN_PAOC options: "" +#! RUN entry: "_GLOBAL::main", result: 1 + +#! CHECKER LLVM AOT rewrite index value +#! RUN_LLVM options: "" +#! RUN entry: "_GLOBAL::main", result: 1 + .function i64 test(i64[] a0, i32 a1) { lda a1 ldarr.64 a0 diff --git a/static_core/tests/checked/llvmaot-gc-intrusion.pa b/static_core/tests/checked/llvmaot-gc-intrusion.pa new file mode 100644 index 000000000..545c781c9 --- /dev/null +++ b/static_core/tests/checked/llvmaot-gc-intrusion.pa @@ -0,0 +1,25 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record A { } + +#! CHECKER Do not relocate if not needed +#! RUN_LLVM options: "--llvm-dump-after" +#! READ_FILE "console.out" +#! INST_NOT "llvm.experimental.gc.relocate" +.function i32 main() { + newobj v1, A + newobj v2, A + ldai 42 + return +} diff --git a/static_core/tests/checked/monitor.pa b/static_core/tests/checked/monitor.pa index 74c7b8411..10abc0a8d 100644 --- a/static_core/tests/checked/monitor.pa +++ b/static_core/tests/checked/monitor.pa @@ -31,6 +31,27 @@ #! INST "LoadObject" #! INST "Monitor" +#! CHECKER Check monitors for inlined functions: lse isn't applied at Regulat AOT +#! RUN_PAOC options: "--compiler-regex='(_GLOBAL::main|_GLOBAL::foo)'" +#! EVENT /Inline,_GLOBAL::main,_GLOBAL::foo,.*STATIC,SUCCESS/ +#! METHOD "_GLOBAL::main" +#! PASS_AFTER "LSE" +#! INST "CallStatic.Inlined" +#! INST "Monitor" +#! INST "LoadObject" +#! INST "Monitor" + +# Check that foo was inlined into main. Then check first Monitor, LoadObject and second Monitor. +#! CHECKER Check monitors for inlined functions: lse isn't applied at LLVM AOT +#! RUN_LLVM options: "--compiler-regex='(_GLOBAL::main|_GLOBAL::foo)' --llvm-dump-after" +#! READ_FILE "console.out" +#! INST "LLVM IR module AFTER LLVM optimizations" +#! INST_NEXT /define protected.*_GLOBAL::main/ +#! INST_NEXT "%__panda_entrypoint_MonitorEnterFastPath_addr" +#! INST_NEXT "getelementptr inbounds i8" +#! INST_NEXT "load i32, ptr addrspace(271)" +#! INST_NEXT "%__panda_entrypoint_MonitorExitFastPath_addr" + .function i32 foo(Obj a0) { call Object.monitorEnter, a0 ldobj a0, Obj.data @@ -63,8 +84,34 @@ #! INST_NOT "CallStatic.Inlined" #! INST_NOT "Monitor" #! INST_NOT "LoadObject" + +#! CHECKER Check monitors for inlined functions: lse is applied at Regular AOT +#! RUN_PAOC options: "--compiler-regex='(_GLOBAL::main1|_GLOBAL::foo)'" +#! EVENT /Inline,_GLOBAL::main1,_GLOBAL::foo,.*STATIC,SUCCESS/ +#! METHOD "_GLOBAL::main1" +#! PASS_AFTER "Inline" +#! INST "CallStatic.Inlined" +#! INST "Monitor" +#! INST_COUNT /LoadObject/,3 +#! INST "Monitor" +#! PASS_AFTER "LSE" +#! INST_COUNT /LoadObject/,1 +#! PASS_AFTER "Lowering" +#! INST_NOT "CallStatic.Inlined" +#! INST_NOT "Monitor" +#! INST_NOT "LoadObject" # Inlined function removed on second BranchElimination after LSE, so Lowering is used +# Check there are no monitors and LoadObject after optimizations in main1 because that is dead code. +#! CHECKER Check monitors for inlined functions: lse isn't applied at LLVM AOT 1 +#! RUN_LLVM options: "--compiler-regex='(_GLOBAL::main1|_GLOBAL::foo)' --llvm-dump-after" +#! READ_FILE "console.out" +#! INST "LLVM IR module AFTER LLVM optimizations" +#! INST_NEXT /define protected.*_GLOBAL::main1/ +#! INST_NEXT_NOT "%__panda_entrypoint_MonitorEnterFastPath_addr" +#! INST_NEXT_NOT "load i32, i32 addrspace(271)" +#! INST_NEXT_NOT "%__panda_entrypoint_MonitorExitFastPath_addr" + .function u1 main1() { newobj v0, Obj ldai 0 diff --git a/static_core/tests/checked/parameter_test.pa b/static_core/tests/checked/parameter_test.pa index 8eb980b01..46accb5a5 100644 --- a/static_core/tests/checked/parameter_test.pa +++ b/static_core/tests/checked/parameter_test.pa @@ -22,6 +22,14 @@ #! EVENT /Compilation,.*foo_u32.*/ #! EVENT /Compilation,.*foo_u64.*/ +#! CHECKER Check method parameters Regular AOT +#! RUN_PAOC options: "--compiler-inlining=false" +#! RUN entry: "_GLOBAL::main" + +#! CHECKER Check method parameters LLVM AOT +#! RUN_LLVM options: "--compiler-inlining=false" +#! RUN entry: "_GLOBAL::main" + .function f32 foo_f32(f32 a0) { fmovi v0, 1.0 lda a0 @@ -144,4 +152,4 @@ exit_failure_6: exit_failure_7: ldai 7 return -} \ No newline at end of file +} diff --git a/static_core/tests/checked/ref_check_elim_test.pa b/static_core/tests/checked/ref_check_elim_test.pa index a4f9fe358..ab8d91370 100644 --- a/static_core/tests/checked/ref_check_elim_test.pa +++ b/static_core/tests/checked/ref_check_elim_test.pa @@ -25,7 +25,33 @@ #! PASS_AFTER "ChecksElimination" #! INST "LoadString" #! INST "NewArray" -#! INST_NOT "RefTypeCheck " +#! INST_NOT "RefTypeCheck" + +#! CHECKER Removing RefTypeCheck for string arrays Regular AOT +#! RUN_PAOC options: "--compiler-regex='_GLOBAL::main'" +#! METHOD "_GLOBAL::main" +#! PASS_AFTER "IrBuilder" +#! INST "RefTypeCheck" +#! INST "LoadString" +#! INST "NewArray" +#! PASS_AFTER "ChecksElimination" +#! INST "LoadString" +#! INST "NewArray" +#! INST_NOT "RefTypeCheck" +#! RUN entry: "_GLOBAL::main" + +#! CHECKER Removing RefTypeCheck for string arrays LLVM AOT +#! RUN_LLVM options: "--compiler-regex='_GLOBAL::main'" +#! METHOD "_GLOBAL::main" +#! PASS_AFTER "IrBuilder" +#! INST "RefTypeCheck" +#! INST "LoadString" +#! INST "NewArray" +#! PASS_AFTER "ChecksElimination" +#! INST "LoadString" +#! INST "NewArray" +#! INST_NOT "RefTypeCheck" +#! RUN entry: "_GLOBAL::main" .function u1 main() { movi v0, 1 #sizeof(array) @@ -48,7 +74,30 @@ #! INST "NewArray" #! PASS_AFTER "ChecksElimination" #! INST "NewArray" -#! INST_NOT "RefTypeCheck " +#! INST_NOT "RefTypeCheck" + +#! CHECKER Removing RefTypeCheck for panda.Object Regular AOT +#! RUN_PAOC options: "--compiler-regex='(_GLOBAL::main1|_GLOBAL::store_string__noinline__)'" +#! METHOD "_GLOBAL::store_string__noinline__" +#! PASS_AFTER "IrBuilder" +#! INST "RefTypeCheck" +#! INST "NewArray" +#! PASS_AFTER "ChecksElimination" +#! INST "NewArray" +#! INST_NOT "RefTypeCheck" +#! RUN entry: "_GLOBAL::main" + +#! CHECKER Removing RefTypeCheck for panda.Object LLVM AOT +#! RUN_LLVM options: "--compiler-regex='(_GLOBAL::main1|_GLOBAL::store_string__noinline__)'" +#! METHOD "_GLOBAL::store_string__noinline__" +#! PASS_AFTER "IrBuilder" +#! INST "RefTypeCheck" +#! INST "NewArray" +#! PASS_AFTER "ChecksElimination" +#! INST "NewArray" +#! INST_NOT "RefTypeCheck" +#! RUN entry: "_GLOBAL::main" + .function panda.Object[] store_string__noinline__(panda.String a0) { movi v0, 1 #sizeof(array) newarr v1, v0, panda.Object[] diff --git a/static_core/tests/checked/stack_overflow.pa b/static_core/tests/checked/stack_overflow.pa index 393cdcc79..f8a0d9087 100644 --- a/static_core/tests/checked/stack_overflow.pa +++ b/static_core/tests/checked/stack_overflow.pa @@ -12,8 +12,16 @@ # limitations under the License. #! CHECKER Stack overflow -#! RUN force_jit: true, options: "--compiler-regex _GLOBAL::__noinline__inc_recursive", entry: "_GLOBAL::main", result: 0 -#! EVENT /Compilation,_GLOBAL::__noinline__inc_recursive,.*,COMPILED/ +#! RUN force_jit: true, options: "--compiler-regex _GLOBAL::__noinline__inc_recursive", entry: "_GLOBAL::main" +#! EVENT /Compilation,_GLOBAL::__noinline__inc_recursive,.*,COMPILED/ + +#! CHECKER Stack overflow at Regular AOT +#! RUN_PAOC options: "--compiler-regex _GLOBAL::__noinline__inc_recursive" +#! RUN entry: "_GLOBAL::main" + +#! DISABLED_CHECKER Stack overflow at LLVM AOT +#! RUN_LLVM options: "--compiler-regex _GLOBAL::__noinline__inc_recursive" +#! RUN entry: "_GLOBAL::main" .record panda.StackOverflowException @@ -49,6 +57,14 @@ catch_stackoverflow_begin: #! RUN force_jit: true, options: "--compiler-regex _GLOBAL::__noinline__inc_recursive", entry: "_GLOBAL::main_no_catch", result: 1 #! EVENT /Compilation,_GLOBAL::__noinline__inc_recursive,.*,COMPILED/ +#! CHECKER Stack overflow unhandled at Regular AOT +#! RUN_PAOC options: "--compiler-regex _GLOBAL::__noinline__inc_recursive" +#! RUN entry: "_GLOBAL::main_no_catch", result: 1 + +#! DISABLED_CHECKER Stack overflow unhandled at LLVM AOT +#! RUN_LLVM options: "--compiler-regex _GLOBAL::__noinline__inc_recursive" +#! RUN entry: "_GLOBAL::main_no_catch", result: 1 + .function i32 main_no_catch() { movi v0, 0 call.short __noinline__inc_recursive, v0 diff --git a/static_core/tests/checked/tlab_test.pa b/static_core/tests/checked/tlab_test.pa index 72d3ff5ef..e27104a6c 100644 --- a/static_core/tests/checked/tlab_test.pa +++ b/static_core/tests/checked/tlab_test.pa @@ -38,6 +38,17 @@ #! EVENT_NEXT /TlabAlloc,.*,16/ #! EVENT_NEXT /TlabAlloc,.*,24/ +#! CHECKER Use TLAB for array and object in LLVMAOT +#! RUN_LLVM options: "--compiler-enable-tlab-events=true --compiler-regex=.*tlab.* --young-shared-space-size=0" +#! RUN options: "--compiler-enable-tlab-events=true", entry: "_GLOBAL::main" +#! TRUE EVENT_COUNT(/SlowpathAlloc,.*/) <= 2 +#! EVENT /TlabAlloc,.*,24/ +#! EVENT_NEXT /TlabAlloc,.*,32/ +#! EVENT_NEXT /TlabAlloc,.*,40/ +#! EVENT_NEXT /TlabAlloc,.*,56/ +#! EVENT_NEXT /TlabAlloc,.*,16/ +#! EVENT_NEXT /TlabAlloc,.*,24/ + #! CHECKER Don't Use TLAB for array and object for STW #! RUN options: "--compiler-hotness-threshold=0 --no-async-jit=false --compiler-enable-jit=true --compiler-enable-tlab-events=true --compiler-check-final=true --gc-type=stw --compiler-regex=.*tlab.* --young-shared-space-size=0", entry: "_GLOBAL::main" #! EVENT /Compilation,.*tlab_array_u64.*/ @@ -49,6 +60,18 @@ #! EVENT /SlowpathAlloc,.*/ #! EVENT_NOT /TlabAlloc,.*/ +#! CHECKER Don't Use TLAB for array and object for STW in AOT +#! RUN_PAOC options: "--compiler-enable-tlab-events=true --gc-type=stw --compiler-regex=.*tlab.*" +#! RUN options: "--compiler-enable-tlab-events=true --gc-type=stw", entry: "_GLOBAL::main" +#! EVENT /SlowpathAlloc,.*/ +#! EVENT_NOT /TlabAlloc,.*/ + +#! CHECKER Don't Use TLAB for array and object for STW in LLVMAOT +#! RUN_LLVM options: "--compiler-enable-tlab-events=true --gc-type=stw --compiler-regex=.*tlab.*" +#! RUN options: "--compiler-enable-tlab-events=true --gc-type=stw", entry: "_GLOBAL::main" +#! EVENT /SlowpathAlloc,.*/ +#! EVENT_NOT /TlabAlloc,.*/ + .record System .record panda.String diff --git a/static_core/tests/checked/verify_aot_tests/verify_aot_test.pa b/static_core/tests/checked/verify_aot_tests/verify_aot_test.pa index a974a1bbe..972d31564 100644 --- a/static_core/tests/checked/verify_aot_tests/verify_aot_test.pa +++ b/static_core/tests/checked/verify_aot_tests/verify_aot_test.pa @@ -64,7 +64,7 @@ #! EVENT /AotManager,.*test.*,CHA_VERIFY_FAILED/ #! CHECKER Test on boot-locations -#! RUN_PAOC options: " --paoc-use-cha=true --paoc-boot-panda-locations /dev/null/arkstdlib.abc" +#! RUN_PAOC options: "--paoc-use-cha=true --paoc-boot-panda-locations /dev/null/arkstdlib.abc" #! EVENT_NOT /Paoc,.*different files/ #! EVENT_NOT /Paoc,.*number of locations/ @@ -82,9 +82,8 @@ #! EVENT /AotManager,.*test.*,ADDED/ #! EVENT /AotManager,.*test.*,VERIFIED/ - #! CHECKER Wrong AOT file with relative path #! RUN_PAOC options: "--panda-files=../../verify_aot_tests_file1.checked/test.abc --paoc-use-cha=true" #! RUN options: "--panda-files=../../verify_aot_tests_file1.checked/test.abc --aot-verify-abs-path=false", entry: "VerifyAotTest::main", abort: 6 #! EVENT /AotManager,.*test.*,ADDED/ -#! EVENT /AotManager,.*test.*,CHA_VERIFY_FAILED/ \ No newline at end of file +#! EVENT /AotManager,.*test.*,CHA_VERIFY_FAILED/ diff --git a/static_core/tests/checked/wrb-arr.pa b/static_core/tests/checked/wrb-arr.pa new file mode 100644 index 000000000..34b91e02b --- /dev/null +++ b/static_core/tests/checked/wrb-arr.pa @@ -0,0 +1,45 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#! CHECKER wrb-arr in LLVM AOT mode +#! RUN_LLVM options: "--llvm-builtin-wrb=true --llvm-dump-after" +#! READ_FILE "console.out" +#! INST_NEXT /define protected.*_GLOBAL::main.*/ +#! INST_NEXT "%__panda_entrypoint_PreWrbFuncNoBridge_addr = load" +#! INST_NEXT /call.*%__panda_entrypoint_PreWrbFuncNoBridge_addr/ +#! INST_NEXT_NOT "%__panda_entrypoint_PreWrbFuncNoBridge_addr2 = load" + +.record Asm{ + u1 asm1 + i32 asm2 +} + +.function i32 main(i32 a0){ + movi v0, 7 + movi v3, 2 + newarr v1, v0, Asm[] + newobj v0, Asm + lda a0 + movi v2, 5 + jeq v2, ok + lda.obj v0 + starr.obj v1, v3 + ldai 0 + jmp exit +ok: + lda.obj v0 + starr.obj v1, v3 + ldai 0 +exit: + return +} diff --git a/static_core/tests/checked/wrb-obj.pa b/static_core/tests/checked/wrb-obj.pa new file mode 100644 index 000000000..579bacb5d --- /dev/null +++ b/static_core/tests/checked/wrb-obj.pa @@ -0,0 +1,42 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#! CHECKER wrb-obj in LLVM AOT mode +#! RUN_LLVM options: "--llvm-builtin-wrb=true --llvm-dump-after --llvm-pre-opt=0" +#! READ_FILE "console.out" +#! INST_NEXT /define protected.*_GLOBAL::main.*/ +#! INST_NEXT "%__panda_entrypoint_PreWrbFuncNoBridge_addr = load" +#! INST_NEXT /call.*%__panda_entrypoint_PreWrbFuncNoBridge_addr/ +#! INST_NEXT_NOT /%__panda_entrypoint_PreWrbFuncNoBridge_addr.* = load/ + +.record Foo { + Foo f +} + +.function i32 main(i32 a0){ + newobj v0, Foo + newobj v1, Foo + lda a0 + movi v2, 5 + jeq v2, ok + lda.obj v1 + stobj v0, Foo.f + ldai 0 + jmp exit +ok: + lda.obj v1 + stobj v0, Foo.f + ldai 0 +exit: + return +} diff --git a/static_core/tests/checked/zero_const_in_save_state.pa b/static_core/tests/checked/zero_const_in_save_state.pa index 11a8920ed..9702427b3 100644 --- a/static_core/tests/checked/zero_const_in_save_state.pa +++ b/static_core/tests/checked/zero_const_in_save_state.pa @@ -15,10 +15,26 @@ #! RUN force_jit: true, options: "--compiler-non-optimizing=true", entry: "_GLOBAL::main0" #! EVENT /Compilation,_GLOBAL::main0,.*COMPILED/ +#! CHECKER Check that save state gracefully handle 0 when optimizations are disabled, test for 5372 at Regular AOT +#! RUN_PAOC options: "--compiler-non-optimizing=true" +#! RUN entry: "_GLOBAL::main0" + +#! CHECKER Check that save state gracefully handle 0 when optimizations are disabled, test for 5372 at LLVM AOT +#! RUN_LLVM options: "--compiler-non-optimizing=true" +#! RUN entry: "_GLOBAL::main0" + #! CHECKER Check that save state correctly propogated in presense of null ref, test for 5372 #! RUN force_jit: true, options: "--compiler-lowering=false --gc-trigger-type=debug", entry: "_GLOBAL::main1" #! EVENT /Compilation,_GLOBAL::main1,.*COMPILED/ +#! CHECKER Check that save state correctly propogated in presense of null ref, test for 5372 at Regular AOT +#! RUN_PAOC options: "--compiler-non-optimizing=false" +#! RUN entry: "_GLOBAL::main0" + +#! CHECKER Check that save state correctly propogated in presense of null ref, test for 5372 at LLVM AOT +#! RUN_LLVM options: "--compiler-non-optimizing=false" +#! RUN entry: "_GLOBAL::main1" + .record E {} .function void __noinline__call(u64 a0) { @@ -66,4 +82,4 @@ catch_begin: ldai 0 return .catchall try_begin, try_end, catch_begin -} \ No newline at end of file +} diff --git a/static_core/tests/cts-assembly/abs-f64-01.pa b/static_core/tests/cts-assembly/abs-f64-01.pa new file mode 100644 index 000000000..8c08f026a --- /dev/null +++ b/static_core/tests/cts-assembly/abs-f64-01.pa @@ -0,0 +1,31 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Assert that intrinsic Math.absF64 works fine +.record Math + +.function f64 Math.absF64(f64 a0) + +.function u1 main() { + fmovi.64 v0, -2.0 + call.short Math.absF64, v0 + fmovi.64 v0, 2.0 + fcmpl.64 v0 + + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/abs-f64-02.pa b/static_core/tests/cts-assembly/abs-f64-02.pa new file mode 100644 index 000000000..690d21bc4 --- /dev/null +++ b/static_core/tests/cts-assembly/abs-f64-02.pa @@ -0,0 +1,31 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Assert that intrinsic Math.absF64 works fine +.record Math + +.function f64 Math.absF64(f64 a0) + +.function u1 main() { + fmovi.64 v0, -2.0 + call.short Math.absF64, v0, v0 + fmovi.64 v0, 2.0 + fcmpl.64 v0 + + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/abs-i32-i64.pa b/static_core/tests/cts-assembly/abs-i32-i64.pa new file mode 100644 index 000000000..09da85d93 --- /dev/null +++ b/static_core/tests/cts-assembly/abs-i32-i64.pa @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Math +.function i32 Math.absI32(i32 a0) +.function i64 Math.absI64(i64 a0) + +.function u1 main(){ + movi v0, 0x80000000 + call.short Math.absI32, v0, v0 + jne v0, exit_failure + movi.64 v0, 0x8000000000000000 + call.short Math.absI64, v0, v0 + jne v0, exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/arrays-checkcast.pa b/static_core/tests/cts-assembly/arrays-checkcast.pa new file mode 100644 index 000000000..737320aba --- /dev/null +++ b/static_core/tests/cts-assembly/arrays-checkcast.pa @@ -0,0 +1,90 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.Object +.record panda.String +.record panda.ClassCastException +.record IO + +.function panda.String panda.ClassCastException.getMessage(panda.ClassCastException a0) +.function void IO.printString(panda.String a0) + +.record A {} + +# Assert that operation checkcast works fine (only throwing an error when cast is not valid) + +.function u1 good_checkcast() { + movi v0, 5 + newarr v1, v0, i64[] + lda.obj v1 + +try_begin: + checkcast i64[] + lda.obj v1 + newarr v2, v0, A[] + lda.obj v2 + checkcast panda.Object[] + ldai 0 + return +try_end: + +catch_block1_begin: + sta.obj v0 + call.virt panda.ClassCastException.getMessage, v0 + sta.obj v0 + call IO.printString, v0 + ldai 1 + return + +catch_block2_begin: + ldai 2 + return + +.catch panda.ClassCastException, try_begin, try_end, catch_block1_begin +.catchall try_begin, try_end, catch_block2_begin +} + +.function u1 main(){ + call.short good_checkcast + jnez exit_failure + movi v0, 5 + newarr v1, v0, i64[] + lda.obj v1 + +try_begin: + # Bad checkcast - throw ClassCastException + checkcast i32[] + ldai 2 + return +try_end: + +catch_block1_begin: + sta.obj v0 + call.virt panda.ClassCastException.getMessage, v0 + sta.obj v0 + call IO.printString, v0 + ldai 0 + return + +catch_block2_begin: + ldai 1 + return + +exit_failure: + ldai 1 + return + +.catch panda.ClassCastException, try_begin, try_end, catch_block1_begin +.catchall try_begin, try_end, catch_block2_begin +} + diff --git a/static_core/tests/cts-assembly/arrays-isinstance.pa b/static_core/tests/cts-assembly/arrays-isinstance.pa new file mode 100644 index 000000000..8b78868ac --- /dev/null +++ b/static_core/tests/cts-assembly/arrays-isinstance.pa @@ -0,0 +1,41 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.Object + +# Assert that operation isinstance works fine + +.record A {} + +.function u1 main(){ + movi v0, 5 + newarr v1, v0, i64[] + lda.obj v1 + isinstance i64[] + jeqz exit_failure + lda.obj v1 + isinstance i32[] + jnez exit_failure + lda.obj v1 + isinstance panda.Object[] + jnez exit_failure + newarr v2, v0, A[] + lda.obj v2 + isinstance panda.Object[] + jeqz exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/call-static-01.pa b/static_core/tests/cts-assembly/call-static-01.pa new file mode 100644 index 000000000..3b4441123 --- /dev/null +++ b/static_core/tests/cts-assembly/call-static-01.pa @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function i64 main() { + movi.64 v0, 999 + movi.64 v1, 69 + call.short foo, v0, v1 + sub2.64 v1 + return.64 +} + +.function i64 foo(i64 a0, i64 a1) { + call.short bar, a1, a0 + return.64 +} + +.function i64 bar(i64 a0, i64 a1) { + lda.64 a0 + return.64 +} diff --git a/static_core/tests/cts-assembly/call-static-02.pa b/static_core/tests/cts-assembly/call-static-02.pa new file mode 100644 index 000000000..640f5868c --- /dev/null +++ b/static_core/tests/cts-assembly/call-static-02.pa @@ -0,0 +1,25 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function i32 main() { + movi v0, 42 + call.short test, v0 + sub2 v0 + + return +} + +.function i32 test(i32 a0) { + lda a0 + return +} diff --git a/static_core/tests/cts-assembly/call-static-03.pa b/static_core/tests/cts-assembly/call-static-03.pa new file mode 100644 index 000000000..6c3dfe371 --- /dev/null +++ b/static_core/tests/cts-assembly/call-static-03.pa @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function i32 main() { + movi v0, 42 + call.short test__noinline__, v0 + sub2 v0 + + return +} + +.function i32 test__noinline__(i32 a0) { + lda a0 + return +} + diff --git a/static_core/tests/cts-assembly/call-static-04.pa b/static_core/tests/cts-assembly/call-static-04.pa new file mode 100644 index 000000000..7954fdc0d --- /dev/null +++ b/static_core/tests/cts-assembly/call-static-04.pa @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function i32 main() { + movi v0, 42 + call.short test__noinline__, v0 + sub2 v0 + + return +} + +.function i32 test__noinline__(i32 a0) { + ldai 42 + return +} + diff --git a/static_core/tests/cts-assembly/call-virtual-01.pa b/static_core/tests/cts-assembly/call-virtual-01.pa new file mode 100644 index 000000000..2f799db1d --- /dev/null +++ b/static_core/tests/cts-assembly/call-virtual-01.pa @@ -0,0 +1,44 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.String +.record IO +.function void IO.printString(panda.String a0) +.function void IO.printI32(i32 a0) + +.record Factory { + i32 i +} + +.function Factory Factory.newFactory(Factory a0) { + newobj v0, Factory + ldai 42 + stobj v0, Factory.i + lda.obj v0 + + return.obj +} + +.function i32 main() { + newobj v0, Factory + call.virt Factory.newFactory, v0 + sta.obj v0 + call.virt Factory.newFactory, v0 + sta.obj v0 + + movi.64 v1, 42 + ldobj v0, Factory.i + i32toi64 + cmp.64 v1 + return +} diff --git a/static_core/tests/cts-assembly/cmp-u32-01.pa b/static_core/tests/cts-assembly/cmp-u32-01.pa new file mode 100644 index 000000000..5b37837dd --- /dev/null +++ b/static_core/tests/cts-assembly/cmp-u32-01.pa @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert ucmp 0xFFFFFFFF, 1 == 1 operation --> ucmp +.function u1 main() { + ldai 0xFFFFFFFF + movi v0, 1 + ucmp v0 + + jltz exit_failure + + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/cmp-u64-01.pa b/static_core/tests/cts-assembly/cmp-u64-01.pa new file mode 100644 index 000000000..5979e450e --- /dev/null +++ b/static_core/tests/cts-assembly/cmp-u64-01.pa @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert ucmp 0xFFFFFFFFFFFFFFFF, 1 == 1 operation --> ucmp.64 +.function u1 main() { + ldai.64 0xFFFFFFFFFFFFFFFF + movi.64 v0, 1 + ucmp.64 v0 + + jltz exit_failure + + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/const-f32-01.pa b/static_core/tests/cts-assembly/const-f32-01.pa new file mode 100644 index 000000000..130929677 --- /dev/null +++ b/static_core/tests/cts-assembly/const-f32-01.pa @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# return f32 (0.0) +.function f32 main() { + ldai 0 + return +} diff --git a/static_core/tests/cts-assembly/const-f64-01.pa b/static_core/tests/cts-assembly/const-f64-01.pa new file mode 100644 index 000000000..5c617c327 --- /dev/null +++ b/static_core/tests/cts-assembly/const-f64-01.pa @@ -0,0 +1,18 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# return f64 (0.0) +.function f64 main() { + fldai.64 0.0 + return.64 +} diff --git a/static_core/tests/cts-assembly/const-f64-02.pa b/static_core/tests/cts-assembly/const-f64-02.pa new file mode 100644 index 000000000..31c7801fc --- /dev/null +++ b/static_core/tests/cts-assembly/const-f64-02.pa @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# return f64 (0.0) + +.function f64 getPi() { + fldai.64 3.1415926 + return.64 +} + +.function i32 main() { + fmovi.64 v0, 3.1415926 + call.short getPi + fcmpl.64 v0 + return +} diff --git a/static_core/tests/cts-assembly/const-f64-03.pa b/static_core/tests/cts-assembly/const-f64-03.pa new file mode 100644 index 000000000..6da187b24 --- /dev/null +++ b/static_core/tests/cts-assembly/const-f64-03.pa @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function f64 getPi() { + fldai.64 3.1415926 + return.64 +} + +.function f64 getOtherNumber() { + fldai.64 2.0405926 + return.64 +} + +.function f64 getPiAndOtherNumberDifference() { + fldai.64 1.101 + return.64 +} + +.function i32 main() { + call.short getOtherNumber + sta.64 v0 + call.short getPi + fsub2.64 v0 + sta.64 v0 + call.short getPiAndOtherNumberDifference + fcmpl.64 v0 + + return +} diff --git a/static_core/tests/cts-assembly/const-f64-04.pa b/static_core/tests/cts-assembly/const-f64-04.pa new file mode 100644 index 000000000..e02d5b04c --- /dev/null +++ b/static_core/tests/cts-assembly/const-f64-04.pa @@ -0,0 +1,919 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record IO +.function void IO.printF64(f64 a0) + +.function f64 getConstant0() { + fldai.64 30.927746268321755 + return.64 +} +.function f64 getConstant0_mirror() { + fldai.64 30.927746268321755 + return.64 +} +.function f64 getConstant1() { + fldai.64 24.84225600662112 + return.64 +} +.function f64 getConstant1_mirror() { + fldai.64 24.84225600662112 + return.64 +} +.function f64 getConstant2() { + fldai.64 55.875992273436005 + return.64 +} +.function f64 getConstant2_mirror() { + fldai.64 55.875992273436005 + return.64 +} +.function f64 getConstant3() { + fldai.64 14.647906742287475 + return.64 +} +.function f64 getConstant3_mirror() { + fldai.64 14.647906742287475 + return.64 +} +.function f64 getConstant4() { + fldai.64 24.456779676852868 + return.64 +} +.function f64 getConstant4_mirror() { + fldai.64 24.456779676852868 + return.64 +} +.function f64 getConstant5() { + fldai.64 17.26475469040577 + return.64 +} +.function f64 getConstant5_mirror() { + fldai.64 17.26475469040577 + return.64 +} +.function f64 getConstant6() { + fldai.64 42.899292167474066 + return.64 +} +.function f64 getConstant6_mirror() { + fldai.64 42.899292167474066 + return.64 +} +.function f64 getConstant7() { + fldai.64 80.19101549361777 + return.64 +} +.function f64 getConstant7_mirror() { + fldai.64 80.19101549361777 + return.64 +} +.function f64 getConstant8() { + fldai.64 31.544109682554257 + return.64 +} +.function f64 getConstant8_mirror() { + fldai.64 31.544109682554257 + return.64 +} +.function f64 getConstant9() { + fldai.64 98.66912140143351 + return.64 +} +.function f64 getConstant9_mirror() { + fldai.64 98.66912140143351 + return.64 +} +.function f64 getConstant10() { + fldai.64 32.79445084683281 + return.64 +} +.function f64 getConstant10_mirror() { + fldai.64 32.79445084683281 + return.64 +} +.function f64 getConstant11() { + fldai.64 0.04935188431176574 + return.64 +} +.function f64 getConstant11_mirror() { + fldai.64 0.04935188431176574 + return.64 +} +.function f64 getConstant12() { + fldai.64 45.466886412846485 + return.64 +} +.function f64 getConstant12_mirror() { + fldai.64 45.466886412846485 + return.64 +} +.function f64 getConstant13() { + fldai.64 42.181858428374156 + return.64 +} +.function f64 getConstant13_mirror() { + fldai.64 42.181858428374156 + return.64 +} +.function f64 getConstant14() { + fldai.64 79.19164409854154 + return.64 +} +.function f64 getConstant14_mirror() { + fldai.64 79.19164409854154 + return.64 +} +.function f64 getConstant15() { + fldai.64 53.297024609470135 + return.64 +} +.function f64 getConstant15_mirror() { + fldai.64 53.297024609470135 + return.64 +} +.function f64 getConstant16() { + fldai.64 59.57958923579125 + return.64 +} +.function f64 getConstant16_mirror() { + fldai.64 59.57958923579125 + return.64 +} +.function f64 getConstant17() { + fldai.64 24.4739766239915 + return.64 +} +.function f64 getConstant17_mirror() { + fldai.64 24.4739766239915 + return.64 +} +.function f64 getConstant18() { + fldai.64 15.227385364177392 + return.64 +} +.function f64 getConstant18_mirror() { + fldai.64 15.227385364177392 + return.64 +} +.function f64 getConstant19() { + fldai.64 10.234142992968842 + return.64 +} +.function f64 getConstant19_mirror() { + fldai.64 10.234142992968842 + return.64 +} +.function f64 getConstant20() { + fldai.64 2.3092305496996923 + return.64 +} +.function f64 getConstant20_mirror() { + fldai.64 2.3092305496996923 + return.64 +} +.function f64 getConstant21() { + fldai.64 56.722262435776926 + return.64 +} +.function f64 getConstant21_mirror() { + fldai.64 56.722262435776926 + return.64 +} +.function f64 getConstant22() { + fldai.64 84.10061219490417 + return.64 +} +.function f64 getConstant22_mirror() { + fldai.64 84.10061219490417 + return.64 +} +.function f64 getConstant23() { + fldai.64 33.105230267946375 + return.64 +} +.function f64 getConstant23_mirror() { + fldai.64 33.105230267946375 + return.64 +} +.function f64 getConstant24() { + fldai.64 70.45692293849578 + return.64 +} +.function f64 getConstant24_mirror() { + fldai.64 70.45692293849578 + return.64 +} +.function f64 getConstant25() { + fldai.64 2.046039088340257 + return.64 +} +.function f64 getConstant25_mirror() { + fldai.64 2.046039088340257 + return.64 +} +.function f64 getConstant26() { + fldai.64 26.75013908258427 + return.64 +} +.function f64 getConstant26_mirror() { + fldai.64 26.75013908258427 + return.64 +} +.function f64 getConstant27() { + fldai.64 5.274590374504829 + return.64 +} +.function f64 getConstant27_mirror() { + fldai.64 5.274590374504829 + return.64 +} +.function f64 getConstant28() { + fldai.64 0.33524057240039706 + return.64 +} +.function f64 getConstant28_mirror() { + fldai.64 0.33524057240039706 + return.64 +} +.function f64 getConstant29() { + fldai.64 25.32086025735528 + return.64 +} +.function f64 getConstant29_mirror() { + fldai.64 25.32086025735528 + return.64 +} +.function f64 getConstant30() { + fldai.64 54.122370512261796 + return.64 +} +.function f64 getConstant30_mirror() { + fldai.64 54.122370512261796 + return.64 +} +.function f64 getConstant31() { + fldai.64 93.4027470663071 + return.64 +} +.function f64 getConstant31_mirror() { + fldai.64 93.4027470663071 + return.64 +} +.function f64 getConstant32() { + fldai.64 86.68094596038769 + return.64 +} +.function f64 getConstant32_mirror() { + fldai.64 86.68094596038769 + return.64 +} +.function f64 getConstant33() { + fldai.64 64.33706791079362 + return.64 +} +.function f64 getConstant33_mirror() { + fldai.64 64.33706791079362 + return.64 +} +.function f64 getConstant34() { + fldai.64 3.470767632687888 + return.64 +} +.function f64 getConstant34_mirror() { + fldai.64 3.470767632687888 + return.64 +} +.function f64 getConstant35() { + fldai.64 54.296866031899214 + return.64 +} +.function f64 getConstant35_mirror() { + fldai.64 54.296866031899214 + return.64 +} +.function f64 getConstant36() { + fldai.64 57.81780032610487 + return.64 +} +.function f64 getConstant36_mirror() { + fldai.64 57.81780032610487 + return.64 +} +.function f64 getConstant37() { + fldai.64 7.462497628387621 + return.64 +} +.function f64 getConstant37_mirror() { + fldai.64 7.462497628387621 + return.64 +} +.function f64 getConstant38() { + fldai.64 28.226276464703638 + return.64 +} +.function f64 getConstant38_mirror() { + fldai.64 28.226276464703638 + return.64 +} +.function f64 getConstant39() { + fldai.64 8.362089753743485 + return.64 +} +.function f64 getConstant39_mirror() { + fldai.64 8.362089753743485 + return.64 +} +.function f64 getConstant40() { + fldai.64 42.20437617613848 + return.64 +} +.function f64 getConstant40_mirror() { + fldai.64 42.20437617613848 + return.64 +} +.function f64 getConstant41() { + fldai.64 12.285055612738772 + return.64 +} +.function f64 getConstant41_mirror() { + fldai.64 12.285055612738772 + return.64 +} +.function f64 getConstant42() { + fldai.64 99.20057028781359 + return.64 +} +.function f64 getConstant42_mirror() { + fldai.64 99.20057028781359 + return.64 +} +.function f64 getConstant43() { + fldai.64 14.959555636530364 + return.64 +} +.function f64 getConstant43_mirror() { + fldai.64 14.959555636530364 + return.64 +} +.function f64 getConstant44() { + fldai.64 16.286878655766333 + return.64 +} +.function f64 getConstant44_mirror() { + fldai.64 16.286878655766333 + return.64 +} +.function f64 getConstant45() { + fldai.64 2.152266803156322 + return.64 +} +.function f64 getConstant45_mirror() { + fldai.64 2.152266803156322 + return.64 +} +.function f64 getConstant46() { + fldai.64 1.2315635654959856 + return.64 +} +.function f64 getConstant46_mirror() { + fldai.64 1.2315635654959856 + return.64 +} +.function f64 getConstant47() { + fldai.64 1.4807704450392478 + return.64 +} +.function f64 getConstant47_mirror() { + fldai.64 1.4807704450392478 + return.64 +} +.function f64 getConstant48() { + fldai.64 6.487206892045638 + return.64 +} +.function f64 getConstant48_mirror() { + fldai.64 6.487206892045638 + return.64 +} +.function f64 getConstant49() { + fldai.64 33.09131326476377 + return.64 +} +.function f64 getConstant49_mirror() { + fldai.64 33.09131326476377 + return.64 +} +.function f64 getConstant50() { + fldai.64 93.85339532340599 + return.64 +} +.function f64 getConstant50_mirror() { + fldai.64 93.85339532340599 + return.64 +} +.function f64 getConstant51() { + fldai.64 17.576984261106233 + return.64 +} +.function f64 getConstant51_mirror() { + fldai.64 17.576984261106233 + return.64 +} +.function f64 getConstant52() { + fldai.64 29.191589917165807 + return.64 +} +.function f64 getConstant52_mirror() { + fldai.64 29.191589917165807 + return.64 +} +.function f64 getConstant53() { + fldai.64 32.284510587862805 + return.64 +} +.function f64 getConstant53_mirror() { + fldai.64 32.284510587862805 + return.64 +} +.function f64 getConstant54() { + fldai.64 67.17064782759999 + return.64 +} +.function f64 getConstant54_mirror() { + fldai.64 67.17064782759999 + return.64 +} +.function f64 getConstant55() { + fldai.64 8.736008070666589 + return.64 +} +.function f64 getConstant55_mirror() { + fldai.64 8.736008070666589 + return.64 +} +.function f64 getConstant56() { + fldai.64 91.76532703304538 + return.64 +} +.function f64 getConstant56_mirror() { + fldai.64 91.76532703304538 + return.64 +} +.function f64 getConstant57() { + fldai.64 71.09152692972367 + return.64 +} +.function f64 getConstant57_mirror() { + fldai.64 71.09152692972367 + return.64 +} +.function f64 getConstant58() { + fldai.64 64.83931487976083 + return.64 +} +.function f64 getConstant58_mirror() { + fldai.64 64.83931487976083 + return.64 +} +.function f64 getConstant59() { + fldai.64 29.277945606143074 + return.64 +} +.function f64 getConstant59_mirror() { + fldai.64 29.277945606143074 + return.64 +} +.function f64 getConstant60() { + fldai.64 44.904282728168795 + return.64 +} +.function f64 getConstant60_mirror() { + fldai.64 44.904282728168795 + return.64 +} +.function f64 getConstant61() { + fldai.64 50.55111188669653 + return.64 +} +.function f64 getConstant61_mirror() { + fldai.64 50.55111188669653 + return.64 +} +.function f64 getConstant62() { + fldai.64 64.90459499445636 + return.64 +} +.function f64 getConstant62_mirror() { + fldai.64 64.90459499445636 + return.64 +} +.function f64 getConstant63() { + fldai.64 43.84512261239283 + return.64 +} +.function f64 getConstant63_mirror() { + fldai.64 43.84512261239283 + return.64 +} +.function i32 main() { + call.short getConstant0 + sta.64 v0 + call.short getConstant0_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant1 + sta.64 v0 + call.short getConstant1_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant2 + sta.64 v0 + call.short getConstant2_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant3 + sta.64 v0 + call.short getConstant3_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant4 + sta.64 v0 + call.short getConstant4_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant5 + sta.64 v0 + call.short getConstant5_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant6 + sta.64 v0 + call.short getConstant6_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant7 + sta.64 v0 + call.short getConstant7_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant8 + sta.64 v0 + call.short getConstant8_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant9 + sta.64 v0 + call.short getConstant9_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant10 + sta.64 v0 + call.short getConstant10_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant11 + sta.64 v0 + call.short getConstant11_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant12 + sta.64 v0 + call.short getConstant12_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant13 + sta.64 v0 + call.short getConstant13_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant14 + sta.64 v0 + call.short getConstant14_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant15 + sta.64 v0 + call.short getConstant15_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant16 + sta.64 v0 + call.short getConstant16_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant17 + sta.64 v0 + call.short getConstant17_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant18 + sta.64 v0 + call.short getConstant18_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant19 + sta.64 v0 + call.short getConstant19_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant20 + sta.64 v0 + call.short getConstant20_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant21 + sta.64 v0 + call.short getConstant21_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant22 + sta.64 v0 + call.short getConstant22_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant23 + sta.64 v0 + call.short getConstant23_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant24 + sta.64 v0 + call.short getConstant24_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant25 + sta.64 v0 + call.short getConstant25_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant26 + sta.64 v0 + call.short getConstant26_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant27 + sta.64 v0 + call.short getConstant27_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant28 + sta.64 v0 + call.short getConstant28_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant29 + sta.64 v0 + call.short getConstant29_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant30 + sta.64 v0 + call.short getConstant30_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant31 + sta.64 v0 + call.short getConstant31_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant32 + sta.64 v0 + call.short getConstant32_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant33 + sta.64 v0 + call.short getConstant33_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant34 + sta.64 v0 + call.short getConstant34_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant35 + sta.64 v0 + call.short getConstant35_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant36 + sta.64 v0 + call.short getConstant36_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant37 + sta.64 v0 + call.short getConstant37_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant38 + sta.64 v0 + call.short getConstant38_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant39 + sta.64 v0 + call.short getConstant39_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant40 + sta.64 v0 + call.short getConstant40_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant41 + sta.64 v0 + call.short getConstant41_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant42 + sta.64 v0 + call.short getConstant42_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant43 + sta.64 v0 + call.short getConstant43_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant44 + sta.64 v0 + call.short getConstant44_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant45 + sta.64 v0 + call.short getConstant45_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant46 + sta.64 v0 + call.short getConstant46_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant47 + sta.64 v0 + call.short getConstant47_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant48 + sta.64 v0 + call.short getConstant48_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant49 + sta.64 v0 + call.short getConstant49_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant50 + sta.64 v0 + call.short getConstant50_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant51 + sta.64 v0 + call.short getConstant51_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant52 + sta.64 v0 + call.short getConstant52_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant53 + sta.64 v0 + call.short getConstant53_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant54 + sta.64 v0 + call.short getConstant54_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant55 + sta.64 v0 + call.short getConstant55_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant56 + sta.64 v0 + call.short getConstant56_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant57 + sta.64 v0 + call.short getConstant57_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant58 + sta.64 v0 + call.short getConstant58_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant59 + sta.64 v0 + call.short getConstant59_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant60 + sta.64 v0 + call.short getConstant60_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant61 + sta.64 v0 + call.short getConstant61_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant62 + sta.64 v0 + call.short getConstant62_mirror + fcmpl.64 v0 + jnez exit_failure + + call.short getConstant63 + sta.64 v0 + call.short IO.printF64, v0, v0 + call.short getConstant63_mirror + fcmpl.64 v0 + jnez exit_failure + + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/floatcast-test-1.pa b/static_core/tests/cts-assembly/floatcast-test-1.pa new file mode 100644 index 000000000..8e219cb4d --- /dev/null +++ b/static_core/tests/cts-assembly/floatcast-test-1.pa @@ -0,0 +1,207 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function i64 func_f64toi64(f64 a0) { + lda.64 a0 + f64toi64 + return.64 +} + +.function i64 func_f64tou64(f64 a0) { + lda.64 a0 + f64tou64 + return.64 +} + +.function i64 func_f32toi64(f32 a0) { + lda a0 + f32toi64 + return.64 +} + +.function i64 func_f32tou64(f32 a0) { + lda a0 + f32tou64 + return.64 +} + +.function i32 func_f64toi32(f64 a0) { + lda.64 a0 + f64toi32 + return +} + +.function i32 func_f64tou32(f64 a0) { + lda.64 a0 + f64tou32 + return +} + +.function i32 func_f32toi32(f32 a0) { + lda a0 + f32toi32 + return +} + +.function i32 func_f32tou32(f32 a0) { + lda a0 + f32tou32 + return +} + +.function i32 main() { + + # f32toi32 (NaN to 0 check) + fmovi v0, 0x7FFFFFFF + call func_f32toi32, v0 + movi v0, 0 + jne v0, exit_failure + + # f64toi64 (NaN to 0 check) + fmovi.64 v0, 0x7FF8000000000000 + call func_f64toi64, v0 + movi.64 v0, 0 + jne v0, exit_failure + + # f32tou32 (NaN to 0 check) + fmovi v0, 0x7FFFFFFF + call func_f32tou32, v0 + movi v0, 0 + jne v0, exit_failure + + # f64tou64 (NaN to 0 check) + fmovi.64 v0, 0x7FF8000000000000 + call func_f64tou64, v0 + movi.64 v0, 0 + jne v0, exit_failure + + # f32toi64 (NaN to 0 check) + fmovi v0, 0x7FFFFFFF + call func_f32toi64, v0 + movi.64 v0, 0 + jne v0, exit_failure + + # f32tou64 (NaN to 0 check) + fmovi v0, 0x7FFFFFFF + call func_f32tou64, v0 + movi.64 v0, 0 + jne v0, exit_failure + + # f32toi32 (MAX_INT32 + 1F to MAX_INT32 check) + fmovi v0, 0x4F000001 + call func_f32toi32, v0 + movi v0, 2147483647 + jne v0, exit_failure + + # f32toi32 (MIN_INT32 + 1F to MIN_INT32 (0x80000000) check) + # (sign bit set to 1 so if we sum float(MIN_INT32) with 1F + # we will get result < float(MIN_INT32)) + fmovi v0, 0xCF000001 + call func_f32toi32, v0 + movi v0, 0x80000000 + jne v0, exit_failure + + # f32tou32 (MAX_UINT32 + 1F to MAX_UINT32 check) + fmovi v0, 0x4F800001 + call func_f32tou32, v0 + movi v0, 4294967295 + jne v0, exit_failure + + # f32tou32 (-1 to 0 check) + fmovi v0, 0xBF800000 + call func_f32tou32, v0 + movi v0, 0 + jne v0, exit_failure + + # f32toi64 (MAX_INT64 + 1F to MAX_INT64 check) + fmovi v0, 0x5F000001 + call func_f32toi64, v0 + movi.64 v0, 9223372036854775807 + jne v0, exit_failure + + # f32toi64 (MIN_INT64 - 1 to MIN_INT64 (0x8000000000000000) check) + # (sign bit set to 1 so if we sum float(MIN_INT64) with 1F + # we will get result < float(MIN_INT64)) + fmovi v0, 0xDF000001 + call func_f32toi64, v0 + movi.64 v0, 0x8000000000000000 + jne v0, exit_failure + + # f32tou64 (MAX_UINT64 + 1F to MAX_UINT64 check) + fmovi v0, 0x5F800001 + call func_f32tou64, v0 + movi.64 v0, 18446744073709551615 + jne v0, exit_failure + + # f32tou64 (-1 to 0 check) + fmovi v0, 0xBF800000 + call func_f32tou64, v0 + movi v0, 0 + jne v0, exit_failure + + # f64toi32 (+inf to MAX_INT32 check) + fmovi.64 v0, 0x7FF0000000000000 + call func_f64toi32, v0 + movi v0, 2147483647 + jne v0, exit_failure + + # f64toi32 (-inf to MIN_INT32 (0x80000000) check) + fmovi.64 v0, 0xFFF0000000000000 + call func_f64toi32, v0 + movi v0, 0x80000000 + jne v0, exit_failure + + # f64tou32 (+inf to UMAX_INT32 check) + fmovi.64 v0, 0x7FF0000000000000 + call func_f64tou32, v0 + movi v0, 4294967295 + jne v0, exit_failure + + # f64tou32 (-inf to 0 check) + fmovi.64 v0, 0xFFF0000000000000 + call func_f64tou32, v0 + movi v0, 0 + jne v0, exit_failure + + # f32toi32 (+inf to MAX_INT32 check) + fmovi v0, 0x7F800000 + call func_f32toi32, v0 + movi v0, 2147483647 + jne v0, exit_failure + + # f32toi32 (-inf to MIN_INT32 (0x80000000) check) + fmovi v0, 0xFF800000 + call func_f32toi32, v0 + movi v0, 0x80000000 + jne v0, exit_failure + + # f32tou32 (+inf to UMAX_INT32 check) + fmovi v0, 0x7F800000 + call func_f32tou32, v0 + movi v0, 4294967295 + jne v0, exit_failure + + # f32tou32 (-inf to 0 check) + fmovi v0, 0xFF800000 + call func_f32tou32, v0 + movi v0, 0 + jne v0, exit_failure + + # All tests done + ldai 0 + return + +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/floatcast-test-2.pa b/static_core/tests/cts-assembly/floatcast-test-2.pa new file mode 120000 index 000000000..267924fa2 --- /dev/null +++ b/static_core/tests/cts-assembly/floatcast-test-2.pa @@ -0,0 +1 @@ +floatcast-test-1.pa \ No newline at end of file diff --git a/static_core/tests/cts-assembly/llvm-options.pa b/static_core/tests/cts-assembly/llvm-options.pa new file mode 100644 index 000000000..4c1b83a08 --- /dev/null +++ b/static_core/tests/cts-assembly/llvm-options.pa @@ -0,0 +1,17 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function u1 main(){ + ldai 0 + return +} diff --git a/static_core/tests/cts-assembly/load-and-init-01.pa b/static_core/tests/cts-assembly/load-and-init-01.pa new file mode 100644 index 000000000..7eb73f1c6 --- /dev/null +++ b/static_core/tests/cts-assembly/load-and-init-01.pa @@ -0,0 +1,32 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Globals { + i32 flag +} + +.function i32 main(){ + ldai 0 + ststatic Globals.flag + ldai 32 + jnez if + jeqz merge +if: + ldai 1 + ststatic Globals.flag + +merge: + ldai 0 + + return +} diff --git a/static_core/tests/cts-assembly/load-and-init-02.pa b/static_core/tests/cts-assembly/load-and-init-02.pa new file mode 100644 index 000000000..dcc2e1792 --- /dev/null +++ b/static_core/tests/cts-assembly/load-and-init-02.pa @@ -0,0 +1,41 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Globals { + i32 x +} + +.function i32 foo(i32 a0) { + lda a0 + jgtz positive + ststatic Globals.x + movi v1, -1 + jmp exit +positive: + ldai 2 + mul2 a0 + ststatic Globals.x + movi v1, 1 +exit: + lda v1 + return +} + +.function i32 main() { + movi v0, 20 + call.short foo, v0 + i32toi64 + movi.64 v0, 1 + cmp.64 v0 + return +} diff --git a/static_core/tests/cts-assembly/long-array.pa b/static_core/tests/cts-assembly/long-array.pa new file mode 100644 index 000000000..cd6582828 --- /dev/null +++ b/static_core/tests/cts-assembly/long-array.pa @@ -0,0 +1,38 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#.array long i32 49 { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 } +.array long i32 999 { 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 } + + +.function i32 main() { + lda.const v0, long + movi v3, 999 + + movi v1, 0 #loop_counter + movi v2, 0 #sum + lda v1 +loop: + jeq v3, loop_exit + lda v1 + ldarr v0 + add2 v2 + sta v2 + inci v1, 1 + lda v1 + jmp loop +loop_exit: + lda v2 + subi 499500 + return +} diff --git a/static_core/tests/cts-assembly/math-fadd-01.pa b/static_core/tests/cts-assembly/math-fadd-01.pa new file mode 100644 index 000000000..8b6e232c7 --- /dev/null +++ b/static_core/tests/cts-assembly/math-fadd-01.pa @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert(5.1 + 7.2 == 12.3) operation --> fadd2.64 +# The difference between this file and math-22.pa is in the absence of abs function +# This file should be considered temporal until we will have call support in +# LLVM AOT +.function u1 main(){ + fldai.64 5.1 + fmovi.64 v0, 7.2 + fadd2.64 v0 + fmovi.64 v0, 12.3 + fcmpl.64 v0 + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-fdiv-01.pa b/static_core/tests/cts-assembly/math-fdiv-01.pa new file mode 100644 index 000000000..7a01bfae4 --- /dev/null +++ b/static_core/tests/cts-assembly/math-fdiv-01.pa @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert(5.0 / 2.5 == 2.0) operation --> fdiv2.64 +.function u1 main() { + fldai.64 5.0 + fmovi.64 v0, 2.5 + fdiv2.64 v0 + fmovi.64 v0, 2.0 + fcmpl.64 v0 + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-fmod-01.pa b/static_core/tests/cts-assembly/math-fmod-01.pa new file mode 100644 index 000000000..c62bb6d89 --- /dev/null +++ b/static_core/tests/cts-assembly/math-fmod-01.pa @@ -0,0 +1,27 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert(12.8 mod 12.3 == 0.5) operation --> fmod2.64 +.function u1 main() { + fldai.64 12.8 + fmovi.64 v0, 12.3 + fmod2.64 v0 + fmovi.64 v0, 0.5 + fcmpl.64 v0 + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-fmul-01.pa b/static_core/tests/cts-assembly/math-fmul-01.pa new file mode 100644 index 000000000..67344321b --- /dev/null +++ b/static_core/tests/cts-assembly/math-fmul-01.pa @@ -0,0 +1,29 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert(5 * 2.5 == 12.5) operation --> fmul2.64 +# This file is heavily influenced by ../cts-assembly/math-25.pa +# The difference between this file and math-25.pa is in the absence of abs function +.function u1 main(){ + fldai.64 5.0 + fmovi.64 v0, 2.5 + fmul2.64 v0 + fmovi.64 v0, 12.5 + fcmpl.64 v0 + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-fneg-01.pa b/static_core/tests/cts-assembly/math-fneg-01.pa new file mode 100644 index 000000000..1298a0b4a --- /dev/null +++ b/static_core/tests/cts-assembly/math-fneg-01.pa @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert(fneg 12.8 == -12.8) operation --> fneg.64 +.function u1 main() { + fldai.64 12.8 + fneg.64 + fmovi.64 v0, -12.8 + fcmpl.64 v0 + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-fneg-02.pa b/static_core/tests/cts-assembly/math-fneg-02.pa new file mode 100644 index 000000000..dfc740e4a --- /dev/null +++ b/static_core/tests/cts-assembly/math-fneg-02.pa @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert(fneg -12.8 == 12.8) operation --> fneg.64 +.function u1 main() { + fldai.64 -12.8 + fneg.64 + fmovi.64 v0, 12.8 + fcmpl.64 v0 + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-fsub-01.pa b/static_core/tests/cts-assembly/math-fsub-01.pa new file mode 100644 index 000000000..491953c52 --- /dev/null +++ b/static_core/tests/cts-assembly/math-fsub-01.pa @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# assert(8.3 - 3.4 == 4.9) operation --> fsub2 +# The difference between this file and math-23.pa is in the absence of abs function +# This file should be considered temporal until we will have call support in +# LLVM AOT +.function u1 main(){ + fldai.64 8.3 + fmovi.64 v0, 3.4 + fsub2.64 v0 + fmovi.64 v0, 4.9 + fcmpl.64 v0 + jnez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-udiv.pa b/static_core/tests/cts-assembly/math-udiv.pa new file mode 100644 index 000000000..5ce7a38d5 --- /dev/null +++ b/static_core/tests/cts-assembly/math-udiv.pa @@ -0,0 +1,30 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Assert that operation divu works fine + +.function u1 main(){ + movi v0, 4294967294 + movi v1, 4294967292 + lda v0 + divu2 v1 + sta v2 + movi v3, 1 + lda v2 + jne v3, exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/math-urem.pa b/static_core/tests/cts-assembly/math-urem.pa new file mode 100644 index 000000000..e18573b81 --- /dev/null +++ b/static_core/tests/cts-assembly/math-urem.pa @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Assert that operation divu works fine + +.record IO +.function void IO.printI32(i32 a0) + +.function u1 main(){ + movi v0, 4294967294 + movi v1, 4294967292 + lda v0 + modu2 v1 + sta v2 + movi v3, 2 + lda v2 + jne v3, exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/min-max-int.pa b/static_core/tests/cts-assembly/min-max-int.pa new file mode 100644 index 000000000..0022115db --- /dev/null +++ b/static_core/tests/cts-assembly/min-max-int.pa @@ -0,0 +1,54 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Math +.function i64 Math.minI64(i64 a0, i64 a1) +.function i32 Math.minI32(i32 a0, i32 a1) +.function i64 Math.maxI64(i64 a0, i64 a1) +.function i32 Math.maxI32(i32 a0, i32 a1) +.function i64 main() { + movi.64 v0, 0x1 + movi.64 v1, 0x2 + call.short Math.minI32, v0, v1 + jne v0, exit_failure + call.short Math.maxI32, v0, v1 + jne v1, exit_failure + + movi.64 v0, -3 + movi.64 v1, -2 + call.short Math.minI32, v0, v1 + jne v0, exit_failure + call.short Math.maxI32, v0, v1 + jne v1, exit_failure + + movi.64 v0, 2147483648 + movi.64 v1, 2147483649 + call.short Math.minI64, v0, v1 + jne v0, exit_failure + call.short Math.maxI64, v0, v1 + jne v1, exit_failure + + movi.64 v0, -2147483650 + movi.64 v1, -2147483649 + call.short Math.minI64, v0, v1 + jne v0, exit_failure + call.short Math.maxI64, v0, v1 + jne v1, exit_failure + + ldai 0 + return + +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/no-inline-0.pa b/static_core/tests/cts-assembly/no-inline-0.pa new file mode 100644 index 000000000..bd7614a07 --- /dev/null +++ b/static_core/tests/cts-assembly/no-inline-0.pa @@ -0,0 +1,25 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function i32 main() { + movi v0, 42 + call.short test__noinline__, v0 + sub2 v0 + + return +} + +.function i32 test__noinline__(i32 a0) { + lda a0 + return +} diff --git a/static_core/tests/cts-assembly/no-inline-1.pa b/static_core/tests/cts-assembly/no-inline-1.pa new file mode 100644 index 000000000..640f5868c --- /dev/null +++ b/static_core/tests/cts-assembly/no-inline-1.pa @@ -0,0 +1,25 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function i32 main() { + movi v0, 42 + call.short test, v0 + sub2 v0 + + return +} + +.function i32 test(i32 a0) { + lda a0 + return +} diff --git a/static_core/tests/cts-assembly/no-inline-2.pa b/static_core/tests/cts-assembly/no-inline-2.pa new file mode 120000 index 000000000..12053482a --- /dev/null +++ b/static_core/tests/cts-assembly/no-inline-2.pa @@ -0,0 +1 @@ +no-inline-1.pa \ No newline at end of file diff --git a/static_core/tests/cts-assembly/no-inline-3.pa b/static_core/tests/cts-assembly/no-inline-3.pa new file mode 120000 index 000000000..12053482a --- /dev/null +++ b/static_core/tests/cts-assembly/no-inline-3.pa @@ -0,0 +1 @@ +no-inline-1.pa \ No newline at end of file diff --git a/static_core/tests/cts-assembly/obj-arr.pa b/static_core/tests/cts-assembly/obj-arr.pa new file mode 100644 index 000000000..c0a83be50 --- /dev/null +++ b/static_core/tests/cts-assembly/obj-arr.pa @@ -0,0 +1,158 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record IO +.function void IO.printI32(i32 a0) +.record Body{ + i32 x + } + +.function Body Crt (i32 a0) { + newobj v0, Body + lda a0 + stobj v0, Body.x + lda.obj v0 + return.obj +} + +.function void Sum(Body[] a0){ + lenarr a0 + sta v3 #size + #inci v3, 2 + movi v4, 0 #loop_counter +loop: + lda v4 + jeq v3, loop_exit + ldarr.obj a0 + sta.obj v5 + ldobj v5, Body.x + sta v0 + call.short IO.printI32, v0, v0 + inci v4, 1 + jmp loop +loop_exit: + return.void +} + +.function void parr(i32[] a0){ + lenarr a0 + sta v3 #size + #movi v3, 32 + movi v4, 0 #loop_counter +loop: + movi v0, 0 + call.short IO.printI32, v0, v0 + movi v0, 77 + call.short IO.printI32, v0, v0 + movi v0, 0 + call.short IO.printI32, v0, v0 + lda v4 + jeq v3, loop_exit + ldarr a0 + sta v0 + call.short IO.printI32, v0, v0 + inci v4, 1 + jmp loop +loop_exit: + return.void +} + +.function void parr1(i32[] a0){ + lenarr a0 + sta v3 #size + #movi v3, 32 + #inci v3, 2 + movi v4, 0 #loop_counter +loop: + movi v0, 0 + call.short IO.printI32, v0, v0 + movi v0, 88 + call.short IO.printI32, v0, v0 + movi v0, 0 + call.short IO.printI32, v0, v0 + lda v4 + jeq v3, loop_exit + ldarr a0 + sta v0 + call.short IO.printI32, v0, v0 + inci v4, 1 + jmp loop +loop_exit: + return.void +} + + + +.function u1 main(){ + movi v0, 1 + newarr v6, v0, i32[] + call.short IO.printI32, v0, v0 + ldai 4444 + movi v2, 0 + starr v6, v2 + movi v2, 4 + newarr v4, v2, Body[] + call.short IO.printI32, v2, v2 + movi v2, 3 + newarr v5, v2, i32[] + ldai 3333 + movi v2, 0 + starr v5, v2 + ldai 2222 + movi v2, 1 + starr v5, v2 + ldai 1111 + movi v2, 2 + starr v5, v2 + # + movi v3, 2 + movi v7, 152 + call.short Crt, v7, v7 + starr.obj v4, v3 + movi v3, 0 + movi v7, 150 + call.short Crt, v7, v7 + starr.obj v4, v3 + movi v3, 1 + movi v7, 151 + call.short Crt, v7, v7 + starr.obj v4, v3 + movi v3, 3 + movi v7, 153 + call.short Crt, v7, v7 + starr.obj v4, v3 + call.short Sum, v4, v4 + call.short IO.printI32, v2, v2 + movi v2, 0 + call.short IO.printI32, v2, v2 + movi v2, 66 + call.short IO.printI32, v2, v2 + movi v2, 0 + call.short IO.printI32, v2, v2 + lenarr v5 + sta v2 #size + call.short IO.printI32, v2, v2 + call.short parr, v6 + + movi v2, 3 + lenarr v5 + jne v2, fail + call.short parr1, v5, v5 + ldai 0 + return +fail: + movi v2, -1 + call.short IO.printI32, v2, v2 + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/obj-checkcast-normal-bug.pa b/static_core/tests/cts-assembly/obj-checkcast-normal-bug.pa new file mode 100644 index 000000000..00a009e24 --- /dev/null +++ b/static_core/tests/cts-assembly/obj-checkcast-normal-bug.pa @@ -0,0 +1,47 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.String +.record panda.ClassCastException +.record IO + +.function panda.String panda.ClassCastException.getMessage(panda.ClassCastException a0) +.function void IO.printString(panda.String a0) + +.record R1 {} +.record R2 {} + +# check ClassCastException + +.function i32 main() { + newobj v0, R1 + lda.obj v0 + +try_begin: + checkcast R2 +try_end: + ldai 10 + jmp end_label + +catch_block_begin: + sta.obj v0 + call.virt panda.ClassCastException.getMessage, v0 + sta.obj v0 + call IO.printString, v0 + ldai 0 + +end_label: + return + +.catch panda.ClassCastException, try_begin, try_end, catch_block_begin +} diff --git a/static_core/tests/cts-assembly/obj-null-01.pa b/static_core/tests/cts-assembly/obj-null-01.pa new file mode 100644 index 000000000..4b1fd91e9 --- /dev/null +++ b/static_core/tests/cts-assembly/obj-null-01.pa @@ -0,0 +1,46 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.NullPointerException + +.record R { + i32 f1 +} + +.function void store_42(R a0) { + ldai 42 + stobj a0, R.f1 + return.void +} + +.function u1 main() { + mov.null v0 + ldai 0 + +try_begin: + call store_42, v0 + ldai 2 + return +try_end: + +catch_block1_begin: + ldai 0 + return + +catch_block2_begin: + ldai 1 + return + +.catch panda.NullPointerException, try_begin, try_end, catch_block1_begin +.catchall try_begin, try_end, catch_block2_begin +} diff --git a/static_core/tests/cts-assembly/obj-null-02.pa b/static_core/tests/cts-assembly/obj-null-02.pa new file mode 100644 index 000000000..5ed7c139f --- /dev/null +++ b/static_core/tests/cts-assembly/obj-null-02.pa @@ -0,0 +1,48 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.String +.record panda.NullPointerException + +.function panda.String panda.NullPointerException.getMessage(panda.NullPointerException a0) + +.record R { + i32 f1 +} + +# check correct frame restoration after NullPointerException. v1 should be restored properly. + +.function u1 main() { + mov.null v0 + newobj v1, R + ldai 42 + stobj v1, R.f1 + +try_begin: + ldobj v0, R.f1 + return +try_end: + +catch_block1_begin: + ldobj v1, R.f1 + movi v2, 42 + sub2 v2 + return + +catch_block2_begin: + ldai 1 + return + +.catch panda.NullPointerException, try_begin, try_end, catch_block1_begin +.catchall try_begin, try_end, catch_block2_begin +} diff --git a/static_core/tests/cts-assembly/obj-null-03.pa b/static_core/tests/cts-assembly/obj-null-03.pa new file mode 100644 index 000000000..9445769cd --- /dev/null +++ b/static_core/tests/cts-assembly/obj-null-03.pa @@ -0,0 +1,53 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.String +.record panda.NullPointerException + +.function panda.String panda.NullPointerException.getMessage(panda.NullPointerException a0) + +.record R { + i32 f1 +} + +# check correct frame restoration after NullPointerException. v1 should be restored properly. + +.function i32 throw_npe__noinline__(R a0) { + ldobj a0, R.f1 + return +} + +.function u1 main() { + mov.null v0 + newobj v1, R + ldai 42 + stobj v1, R.f1 + +try_begin: + call throw_npe__noinline__, v0 + return +try_end: + +catch_block1_begin: + ldobj v1, R.f1 + movi v2, 42 + sub2 v2 + return + +catch_block2_begin: + ldai 1 + return + +.catch panda.NullPointerException, try_begin, try_end, catch_block1_begin +.catchall try_begin, try_end, catch_block2_begin +} diff --git a/static_core/tests/cts-assembly/obj-null-04.pa b/static_core/tests/cts-assembly/obj-null-04.pa new file mode 100644 index 000000000..13b51ec19 --- /dev/null +++ b/static_core/tests/cts-assembly/obj-null-04.pa @@ -0,0 +1,49 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.NullPointerException + +.record R { + i32 f1 +} + +.function i32 store_42(R a0) { + ldai 42 + stobj a0, R.f1 + return +} + +.function i32 will_be_deoptimized() { + mov.null v0 + +try_begin: + call store_42, v0 + ldai 1 + return +try_end: + +catch_block1_begin: + ldai 0 + return + +.catch panda.NullPointerException, try_begin, try_end, catch_block1_begin +} + +.function u1 main() { + call will_be_deoptimized + jnez fail + return +fail: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/obj-null-05.pa b/static_core/tests/cts-assembly/obj-null-05.pa new file mode 100644 index 000000000..e64c17280 --- /dev/null +++ b/static_core/tests/cts-assembly/obj-null-05.pa @@ -0,0 +1,49 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.NullPointerException + +.record R { + i32 f1 +} + +.function i32 store_42(R a0) { + ldai 42 + stobj a0, R.f1 + return +} + +.function i32 will_be_deoptimized() { + mov.null v0 + +try_begin: + call store_42, v0 +try_end: + ldai 1 + return + +catch_block1_begin: + ldai 0 + return + +.catch panda.NullPointerException, try_begin, try_end, catch_block1_begin +} + +.function u1 main() { + call will_be_deoptimized + jnez fail + return +fail: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/obj-null-06.pa b/static_core/tests/cts-assembly/obj-null-06.pa new file mode 100644 index 000000000..1b1e0360b --- /dev/null +++ b/static_core/tests/cts-assembly/obj-null-06.pa @@ -0,0 +1,50 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.NullPointerException +.record R { + i32 f1 +} +.function i32 store_42(R a0) { + ldai 42 + stobj a0, R.f1 + return +} +.function i32 will_be_deoptimized(R a0) { +try_begin: + call store_42, a0 +try_end: + newobj v1, R + jeqz skip + call store_42, v1 +skip: + call store_42, v1 + ldai 1 + return + +catch_block1_begin: + ldai 0 + return +.catch panda.NullPointerException, try_begin, try_end, catch_block1_begin +} + +.function u1 main() { + mov.null v0 + call will_be_deoptimized, v0 + jnez fail + return +fail: + ldai 1 + return +} + diff --git a/static_core/tests/cts-assembly/phi-f64-01.pa b/static_core/tests/cts-assembly/phi-f64-01.pa new file mode 100644 index 000000000..b81b79003 --- /dev/null +++ b/static_core/tests/cts-assembly/phi-f64-01.pa @@ -0,0 +1,22 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.function f64 main() { + fmovi.64 v0, 2.0 + ldai -1 + jgez _exit + fmovi.64 v0, 1.0 +_exit: + lda.64 v0 + return.64 +} \ No newline at end of file diff --git a/static_core/tests/cts-assembly/shl31.pa b/static_core/tests/cts-assembly/shl31.pa new file mode 100644 index 000000000..0641281bc --- /dev/null +++ b/static_core/tests/cts-assembly/shl31.pa @@ -0,0 +1,71 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# ==================== +# METHODS +.function u1 main() { + movi v0, 0x1 + mov v4, v0 + movi v0, 0x1f + mov v5, v0 + mov v0, v4 + movi v1, 0xffffffffffffffff + shl v0, v1 + sta v0 + mov v1, v4 + movi v2, 0xffffffffffffffff + mov v3, v5 + and v3, v2 + sta v2 + shl v1, v2 + sta v1 + lda v0 + jeq v1, jump_label_0 + movi v0, 0x2 + lda v0 + return + jump_label_0: mov v0, v4 + movi v1, 0xf0 + shl v0, v1 + sta v0 + mov v1, v4 + movi v2, 0xf0 + mov v3, v5 + and v3, v2 + sta v2 + shl v1, v2 + sta v1 + lda v0 + jeq v1, jump_label_1 + movi v0, 0x2 + lda v0 + return + jump_label_1: mov v0, v4 + movi v1, 0x80 + shl v0, v1 + sta v0 + mov v1, v4 + movi v2, 0x80 + mov v3, v5 + and v3, v2 + sta v2 + shl v1, v2 + sta v1 + lda v0 + jne v1, jump_label_2 + movi v0, 0x0 + jmp jump_label_3 + jump_label_2: movi v0, 0x2 + jump_label_3: lda v0 + return +} diff --git a/static_core/tests/cts-assembly/sinf64.pa b/static_core/tests/cts-assembly/sinf64.pa new file mode 100644 index 000000000..4d1eab91d --- /dev/null +++ b/static_core/tests/cts-assembly/sinf64.pa @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Math +.function f64 Math.sin(f64 a0) +.function f64 Math.absF64(f64 a0) + +.function u1 main(){ + fmovi.64 v0, -0.20944 + fmovi.64 v1, -0.2079120 + fmovi.64 v2, 1e-6 + call.short Math.sin, v0, v0 + fsub2.64 v1 + sta.64 v1 + call.short Math.absF64, v1, v1 + fcmpl.64 v2 + jgez exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/small-fields-01.pa b/static_core/tests/cts-assembly/small-fields-01.pa new file mode 100644 index 000000000..2f728970f --- /dev/null +++ b/static_core/tests/cts-assembly/small-fields-01.pa @@ -0,0 +1,53 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record R { + u1 field1 + u1 field2 + u1 field3 +} + +.function void R.ctor(R a0, u1 a1, u1 a2) { + lda a1 + stobj a0, R.field1 + lda a2 + stobj a0, R.field2 + lda a1 + stobj a0, R.field3 + return.void +} + +.function u1 main() { + movi v0, 1 + movi v1, 0 + initobj R.ctor, v0, v1 + sta.obj v8 + + ldobj v8, R.field1 + jne v0, error1 + ldobj v8, R.field2 + jne v1, error2 + ldobj v8, R.field3 + jne v0, error3 + ldai 0 + return +error1: + ldai 1 + return +error2: + ldai 2 + return +error3: + ldai 3 + return +} diff --git a/static_core/tests/cts-assembly/small-fields-02.pa b/static_core/tests/cts-assembly/small-fields-02.pa new file mode 100644 index 000000000..92c1621c1 --- /dev/null +++ b/static_core/tests/cts-assembly/small-fields-02.pa @@ -0,0 +1,41 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record R { + u16 field +} + +.function void R.ctor(R a0) { + ldai 65535 + stobj a0, R.field + return.void +} + +.function i32 main(){ + initobj R.ctor + sta.obj v0 + + movi v1, 1 + ldobj v0, R.field + add2 v1 + sta v2 + ldai 65536 + jne v2, exit_error + + ldai 0 + return + +exit_error: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/small-static-fields-01.pa b/static_core/tests/cts-assembly/small-static-fields-01.pa new file mode 100644 index 000000000..c00c35bae --- /dev/null +++ b/static_core/tests/cts-assembly/small-static-fields-01.pa @@ -0,0 +1,38 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Globals{ + i8 flag0 + i8 flag1 + i8 flag2 +} + +.function i32 main(){ + ldai 1 + ststatic Globals.flag1 + + ldstatic Globals.flag0 + jnez exit_error + + ldstatic Globals.flag2 + jnez exit_error + + ldai 0 + return + +exit_error: + ldai 1 + + return +} + diff --git a/static_core/tests/cts-assembly/small-static-fields-02.pa b/static_core/tests/cts-assembly/small-static-fields-02.pa new file mode 100644 index 000000000..0168f09ae --- /dev/null +++ b/static_core/tests/cts-assembly/small-static-fields-02.pa @@ -0,0 +1,35 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record R { + u16 field +} + +.function i32 main(){ + ldai 65535 + ststatic R.field + + movi v0, 1 + ldstatic R.field + add2 v0 + sta v2 + ldai 65536 + jne v2, exit_error + + ldai 0 + return + +exit_error: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/test-max.pa b/static_core/tests/cts-assembly/test-max.pa new file mode 100644 index 000000000..6bec439f3 --- /dev/null +++ b/static_core/tests/cts-assembly/test-max.pa @@ -0,0 +1,88 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Math +.function f32 Math.maxF32(f32 a0, f32 a1) + +.function i32 main() { + + fmovi v5, 0x7fffffff + fmovi v6, 0x7fffffff + call.short Math.maxF32, v6, v5 + sta v7 + fcmpl v5 + movi v8, -1 + jne v8, exit_failure + lda v7 + fcmpg v5 + movi v8, 1 + jne v8, exit_failure + + fmovi v5, 0x7fffffff + fmovi v6, 0x00000000 + call.short Math.maxF32, v6, v5 + sta v7 + fcmpl v5 + movi v8, -1 + jne v8, exit_failure + lda v7 + fcmpg v5 + movi v8, 1 + jne v8, exit_failure + + fmovi v5, 0x00000000 + fmovi v6, 0x00000000 + fmovi v7, 0.00001 + fmovi v8, -0.00001 + call.short Math.maxF32, v6, v5 + sta v9 + fcmpg v7 + jgtz exit_failure + lda v9 + fcmpg v8 + jltz exit_failure + + fmovi v5, -15.7 + fmovi v6, -25.45 + fmovi v7, -15.6999 + fmovi v8, -15.7001 + + call.short Math.maxF32, v5, v6 + sta v9 + fcmpg v7 + jgtz exit_failure + lda v9 + fcmpg v8 + jltz exit_failure + + fmovi v5, 1.14 + fmovi v6, 2.57 + fmovi v7, 2.57001 + fmovi v8, 2.56999 + call.short Math.maxF32, v6, v5 + sta v9 + fcmpg v7 + jgtz exit_failure + lda v9 + fcmpg v8 + jltz exit_failure + + ldai 0 + return +exit_failure: + ldai 1 + return +} + + + diff --git a/static_core/tests/cts-assembly/test-min.pa b/static_core/tests/cts-assembly/test-min.pa new file mode 100644 index 000000000..07309d89e --- /dev/null +++ b/static_core/tests/cts-assembly/test-min.pa @@ -0,0 +1,88 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record Math +.function f32 Math.minF32(f32 a0, f32 a1) + +.function i32 main() { + + fmovi v5, 0x7fffffff + fmovi v6, 0x7fffffff + call.short Math.minF32, v6, v5 + sta v7 + fcmpl v5 + movi v8, -1 + jne v8, exit_failure + lda v7 + fcmpg v5 + movi v8, 1 + jne v8, exit_failure + + fmovi v5, 0x7fffffff + fmovi v6, 0x00000000 + call.short Math.minF32, v6, v5 + sta v7 + fcmpl v5 + movi v8, -1 + jne v8, exit_failure + lda v7 + fcmpg v5 + movi v8, 1 + jne v8, exit_failure + + fmovi v5, 0x00000000 + fmovi v6, 0x00000000 + fmovi v7, 0.00001 + fmovi v8, -0.00001 + call.short Math.minF32, v6, v5 + sta v9 + fcmpg v7 + jgtz exit_failure + lda v9 + fcmpg v8 + jltz exit_failure + + fmovi v5, -15.7 + fmovi v6, 5.45 + fmovi v7, -15.6999 + fmovi v8, -15.7001 + + call.short Math.minF32, v5, v6 + sta v9 + fcmpg v7 + jgtz exit_failure + lda v9 + fcmpg v8 + jltz exit_failure + + fmovi v5, 3.14 + fmovi v6, 2.57 + fmovi v7, 2.57001 + fmovi v8, 2.56999 + call.short Math.minF32, v6, v5 + sta v9 + fcmpg v7 + jgtz exit_failure + lda v9 + fcmpg v8 + jltz exit_failure + + ldai 0 + return +exit_failure: + ldai 1 + return +} + + + diff --git a/static_core/tests/cts-assembly/type-coercion-01.pa b/static_core/tests/cts-assembly/type-coercion-01.pa new file mode 100644 index 000000000..1fec62869 --- /dev/null +++ b/static_core/tests/cts-assembly/type-coercion-01.pa @@ -0,0 +1,33 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Call foo, multiply it by 2 and expect the result to be equal to 26 +.function u1 foo() { + ldai 13 + return +} + +.function i32 main() { + call.short foo + sta v0 + add2 v0 + movi v1, 26 + jeq v1, exit_ok + + ldai 1 + return + +exit_ok: + ldai 0 + return +} \ No newline at end of file diff --git a/static_core/tests/cts-assembly/type-coercion-02.pa b/static_core/tests/cts-assembly/type-coercion-02.pa new file mode 100644 index 000000000..1974c7b29 --- /dev/null +++ b/static_core/tests/cts-assembly/type-coercion-02.pa @@ -0,0 +1,51 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Assert that operations with array of u8 works fine +# Same as arrays-02.pa but against u8[] + +# for (i64 i = 0; i < 5; i++) { +# array[i] = i; +# } +# for (i64 i = 4; i >= 0; i--) { +# assert_eq(i, array[i]); +# } + +.function u1 main(){ + movi v0, 5 + newarr v1, v0, u8[] + movi v2, 0 + ldai 0 +loop: + jeq v0, loop_exit + starr.8 v1, v2 + inci v2, 1 + lda v2 + jmp loop +loop_exit: + subi 1 + sta v2 +loop2: + jltz loop2_exit + ldarru.8 v1 + jne v2, exit_failure + inci v2, -1 + lda v2 + jmp loop2 +loop2_exit: + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/type-coercion-03.pa b/static_core/tests/cts-assembly/type-coercion-03.pa new file mode 100644 index 000000000..5ad5f524a --- /dev/null +++ b/static_core/tests/cts-assembly/type-coercion-03.pa @@ -0,0 +1,43 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The test intends to check if we're widening array elements correctly in ldarr.* instructions. +# We have to do it to conform the specification: +# > If element size is smaller then 32 bits, it will be zero or sign extended (depending on bytecode) to i32 + +# short[] array = new short[1]; +# array[0] = 1000; +# int result = 8; +# result = array[0] + result +# assert(result == 1008) + +.function u1 main() { + movi v0, 1 # sizeof(array) + newarr v1, v0, i16[] + movi v2, 0 + ldai 1000 + starr.16 v1, v2 # array[0] = 1000 + + movi v2, 8 + ldai 0 + ldarr.16 v1 + add2 v2 + sta v3 + ldai 1008 + jne v3, exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/type-coercion-04.pa b/static_core/tests/cts-assembly/type-coercion-04.pa new file mode 100644 index 000000000..6f1dedad2 --- /dev/null +++ b/static_core/tests/cts-assembly/type-coercion-04.pa @@ -0,0 +1,64 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# u8 array = new u8[5]; +# for (i64 i = 0; i < 5; i++) { +# array[i] = (implicit truncation to u8) 257; +# } +# for (i64 i = 4; i >= 0; i--) { +# assert(1 == array[i]); +# } + +.record IO +.function void IO.printI32(i32 a0) + +.function u1 main() { + movi v0, 5 # sizeof(array) + newarr v1, v0, u8[] + movi v2, 0 + movi v3, 257 + lda v2 +loop: + jeq v0, loop_exit + + lda v3 + starr.8 v1, v2 + inci v2, 1 + lda v2 + jmp loop +loop_exit: + subi 1 + sta v2 + movi v3, 1 + +loop2: + lda v2 + jltz loop2_exit + ldarru.8 v1 + + sta v4 + + call.short IO.printI32, v4 + + lda v4 + + jne v3, exit_failure + inci v2, -1 + jmp loop2 +loop2_exit: + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/cts-assembly/type-coercion-05.pa b/static_core/tests/cts-assembly/type-coercion-05.pa new file mode 100644 index 000000000..46991de0d --- /dev/null +++ b/static_core/tests/cts-assembly/type-coercion-05.pa @@ -0,0 +1,43 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# The test intends to check if we're widening array elements correctly in ldarr.* instructions. +# We have to do it to conform the specification: +# > If element size is smaller then 32 bits, it will be zero or sign extended (depending on bytecode) to i32 + +# u16[] array = new u16[1]; +# array[0] = 65535; +# int result = 1; +# result = array[0] + result +# assert(result == 65536) + +.function u1 main() { + movi v0, 1 # sizeof(array) + newarr v1, v0, u16[] + movi v2, 0 + ldai 65535 + starr.16 v1, v2 # array[0] = 65535 + + movi v2, 1 + ldai 0 + ldarru.16 v1 + add2 v2 + sta v3 + ldai 65536 + jne v3, exit_failure + ldai 0 + return +exit_failure: + ldai 1 + return +} diff --git a/static_core/tests/irtoc-interpreter-tests/array-npe-1.pa b/static_core/tests/irtoc-interpreter-tests/array-npe-1.pa new file mode 100644 index 000000000..2ca737dbc --- /dev/null +++ b/static_core/tests/irtoc-interpreter-tests/array-npe-1.pa @@ -0,0 +1,34 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.NullPointerException + +.function i32 main() { + mov.null v0 + movi v1, 0x1 + + try_begin: + ldai 2 + starr v0, v1 + jmp try_end + + catch_block_begin: + ldai 0 + return + + try_end: + ldai 1 + return + + .catch panda.NullPointerException, try_begin, try_end, catch_block_begin +} \ No newline at end of file diff --git a/static_core/tests/irtoc-interpreter-tests/array-npe-2.pa b/static_core/tests/irtoc-interpreter-tests/array-npe-2.pa new file mode 100644 index 000000000..826aae249 --- /dev/null +++ b/static_core/tests/irtoc-interpreter-tests/array-npe-2.pa @@ -0,0 +1,39 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.NullPointerException + +.function void foo(i32[] a0, i32 a1) { + ldai 2 + starr a0, a1 + return.void +} + +.function i32 main() { + mov.null v0 + movi v1, 0x1 + + try_begin: + call foo, v0, v1 + jmp try_end + + catch_block_begin: + ldai 0 + return + + try_end: + ldai 1 + return + + .catch panda.NullPointerException, try_begin, try_end, catch_block_begin +} \ No newline at end of file diff --git a/static_core/tests/irtoc-interpreter-tests/array-oob-1.pa b/static_core/tests/irtoc-interpreter-tests/array-oob-1.pa new file mode 100644 index 000000000..060289ade --- /dev/null +++ b/static_core/tests/irtoc-interpreter-tests/array-oob-1.pa @@ -0,0 +1,35 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.ArrayIndexOutOfBoundsException + +.function i32 main() { + movi v0, 0x5 + newarr v1, v0, i32[] + movi v2, 0x10 + + try_begin: + ldai 2 + starr v1, v2 + jmp try_end + + catch_block_begin: + ldai 0 + return + + try_end: + ldai 1 + return + + .catch panda.ArrayIndexOutOfBoundsException, try_begin, try_end, catch_block_begin +} \ No newline at end of file diff --git a/static_core/tests/irtoc-interpreter-tests/array-oob-2.pa b/static_core/tests/irtoc-interpreter-tests/array-oob-2.pa new file mode 100644 index 000000000..1bf9c0112 --- /dev/null +++ b/static_core/tests/irtoc-interpreter-tests/array-oob-2.pa @@ -0,0 +1,40 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +.record panda.ArrayIndexOutOfBoundsException + +.function void foo(i32[] a0, i32 a1) { + ldai 2 + starr a0, a1 + return.void +} + +.function i32 main() { + movi v0, 0x5 + newarr v1, v0, i32[] + movi v2, 0x10 + + try_begin: + call foo, v1, v2 + jmp try_end + + catch_block_begin: + ldai 0 + return + + try_end: + ldai 1 + return + + .catch panda.ArrayIndexOutOfBoundsException, try_begin, try_end, catch_block_begin +} \ No newline at end of file diff --git a/static_core/tests/regression/fmodf.pa b/static_core/tests/regression/fmodf.pa new file mode 100644 index 000000000..81508fbf3 --- /dev/null +++ b/static_core/tests/regression/fmodf.pa @@ -0,0 +1,54 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# fmodf(a0, a1) == a2 +.function i32 fmod(f32 a0, f32 a1, f32 a2) { + lda a0 + fmod2 a1 + fcmpl a2 + return +} + +.function i32 main() { + fmovi v0, 5.3 + fmovi v1, 2.0 + fmovi v2, 1.3000002 + call fmod, v0, v1, v2 + jnez end + + fmovi v0, -18.5 + fmovi v1, 4.2 + fmovi v2, -1.7000008 + call fmod, v0, v1, v2 + jnez end + + fmovi v0, 2.1 + fmovi v1, 4.2 + fmovi v2, 2.0999999 + call fmod, v0, v1, v2 + jnez end + + fmovi v0, 18.5 + fmovi v1, 4.2 + fmovi v2, 1.7000008 + call fmod, v0, v1, v2 + jnez end + + fmovi v0, 4.0 + fmovi v1, 4.0 + fmovi v2, 0.0 + call fmod, v0, v1, v2 + +end: + return +} -- Gitee From 4443f039046ec228d16ae48baf97f4cf6c58b29e Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Thu, 14 Nov 2024 12:48:07 +0300 Subject: [PATCH 26/36] Try to adjust Panda SDK stuff --- static_core/scripts/sdk/build_sdk_lib | 5 ++++- static_core/scripts/sdk/linux_arm64_host_tools.txt | 2 ++ static_core/scripts/sdk/linux_host_tools.txt | 2 ++ static_core/scripts/sdk/ohos_arm64.txt | 2 ++ static_core/scripts/sdk/test2_file_list_expected.txt | 6 ++++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/static_core/scripts/sdk/build_sdk_lib b/static_core/scripts/sdk/build_sdk_lib index 6f4f7b6cf..bfcef5083 100644 --- a/static_core/scripts/sdk/build_sdk_lib +++ b/static_core/scripts/sdk/build_sdk_lib @@ -66,7 +66,10 @@ function linux_arm64_tools() { local linux_arm64_build_dir="$SDK_BUILD_ROOT/linux_arm64_host_tools" local linux_arm64_cmake_args=" \ -DCMAKE_TOOLCHAIN_FILE=cmake/toolchain/cross-clang-14-qemu-aarch64.cmake \ - -DPANDA_WITH_ECMASCRIPT=ON" + -DPANDA_LLVM_BACKEND=ON \ + -DLLVM_HOST_PATH=/opt/llvm-15-${PANDA_SDK_BUILD_TYPE,,}-x86_64 \ + -DLLVM_TARGET_PATH=/opt/llvm-15-${PANDA_SDK_BUILD_TYPE,,}-aarch64" + local linux_arm64_build_targets="ark ark_aot ark_disasm ark_link es2panda e2p_test_plugin etsnative" build_panda "$linux_arm64_build_dir" "$linux_arm64_cmake_args" "$linux_arm64_build_targets" copy_into_sdk "$linux_arm64_build_dir" "$PANDA_SDK_PATH/linux_arm64_host_tools" "$SCRIPT_DIR"/linux_arm64_host_tools.txt diff --git a/static_core/scripts/sdk/linux_arm64_host_tools.txt b/static_core/scripts/sdk/linux_arm64_host_tools.txt index 2f9de0b7e..58fb69af0 100644 --- a/static_core/scripts/sdk/linux_arm64_host_tools.txt +++ b/static_core/scripts/sdk/linux_arm64_host_tools.txt @@ -22,3 +22,5 @@ lib/libhmicui18n.z.so lib/libhmicuuc.z.so lib/libinit_icu.so lib/libirtoc.so +lib/libLLVM-15.so +lib/libllvmbackend.so diff --git a/static_core/scripts/sdk/linux_host_tools.txt b/static_core/scripts/sdk/linux_host_tools.txt index 2f9de0b7e..58fb69af0 100644 --- a/static_core/scripts/sdk/linux_host_tools.txt +++ b/static_core/scripts/sdk/linux_host_tools.txt @@ -22,3 +22,5 @@ lib/libhmicui18n.z.so lib/libhmicuuc.z.so lib/libinit_icu.so lib/libirtoc.so +lib/libLLVM-15.so +lib/libllvmbackend.so diff --git a/static_core/scripts/sdk/ohos_arm64.txt b/static_core/scripts/sdk/ohos_arm64.txt index e53fb9b46..0a39a3e46 100644 --- a/static_core/scripts/sdk/ohos_arm64.txt +++ b/static_core/scripts/sdk/ohos_arm64.txt @@ -20,4 +20,6 @@ lib/libets_interop_js_napi.so lib/libhmicui18n.z.so lib/libhmicuuc.z.so lib/libinit_icu.a +lib/libLLVM-15.so +lib/libllvmbackend.so plugins/ecmascript/ecmastdlib/ecmastdlib.abc diff --git a/static_core/scripts/sdk/test2_file_list_expected.txt b/static_core/scripts/sdk/test2_file_list_expected.txt index 6b3e624e9..a220e623d 100644 --- a/static_core/scripts/sdk/test2_file_list_expected.txt +++ b/static_core/scripts/sdk/test2_file_list_expected.txt @@ -14,6 +14,7 @@ build-sdk/sdk/linux_arm64_host_tools/bin/ark_disasm build-sdk/sdk/linux_arm64_host_tools/bin/ark_link build-sdk/sdk/linux_arm64_host_tools/bin/es2panda build-sdk/sdk/linux_arm64_host_tools/lib +build-sdk/sdk/linux_arm64_host_tools/lib/libLLVM-15.so build-sdk/sdk/linux_arm64_host_tools/lib/libarkaotmanager.so build-sdk/sdk/linux_arm64_host_tools/lib/libarkassembler.so build-sdk/sdk/linux_arm64_host_tools/lib/libarkbase.so @@ -32,6 +33,7 @@ build-sdk/sdk/linux_arm64_host_tools/lib/libetsnative.so build-sdk/sdk/linux_arm64_host_tools/lib/libhmicui18n.z.so build-sdk/sdk/linux_arm64_host_tools/lib/libhmicuuc.z.so build-sdk/sdk/linux_arm64_host_tools/lib/libinit_icu.so +build-sdk/sdk/linux_arm64_host_tools/lib/libllvmbackend.so build-sdk/sdk/linux_host_tools build-sdk/sdk/linux_host_tools/bin build-sdk/sdk/linux_host_tools/bin/ark @@ -40,6 +42,7 @@ build-sdk/sdk/linux_host_tools/bin/ark_disasm build-sdk/sdk/linux_host_tools/bin/ark_link build-sdk/sdk/linux_host_tools/bin/es2panda build-sdk/sdk/linux_host_tools/lib +build-sdk/sdk/linux_host_tools/lib/libLLVM-15.so build-sdk/sdk/linux_host_tools/lib/libarkaotmanager.so build-sdk/sdk/linux_host_tools/lib/libarkassembler.so build-sdk/sdk/linux_host_tools/lib/libarkbase.so @@ -59,6 +62,7 @@ build-sdk/sdk/linux_host_tools/lib/libhmicui18n.z.so build-sdk/sdk/linux_host_tools/lib/libhmicuuc.z.so build-sdk/sdk/linux_host_tools/lib/libinit_icu.so build-sdk/sdk/linux_host_tools/lib/libirtoc.so +build-sdk/sdk/linux_host_tools/lib/libllvmbackend.so build-sdk/sdk/ohos_arm64 build-sdk/sdk/ohos_arm64/bin build-sdk/sdk/ohos_arm64/bin/ark @@ -75,6 +79,7 @@ build-sdk/sdk/ohos_arm64/include/third_party build-sdk/sdk/ohos_arm64/include/tools build-sdk/sdk/ohos_arm64/include/verification build-sdk/sdk/ohos_arm64/lib +build-sdk/sdk/ohos_arm64/lib/libLLVM-15.so build-sdk/sdk/ohos_arm64/lib/libarkaotmanager.so build-sdk/sdk/ohos_arm64/lib/libarkassembler.so build-sdk/sdk/ohos_arm64/lib/libarkbase.so @@ -95,6 +100,7 @@ build-sdk/sdk/ohos_arm64/lib/libets_interop_js_napi.so build-sdk/sdk/ohos_arm64/lib/libhmicui18n.z.so build-sdk/sdk/ohos_arm64/lib/libhmicuuc.z.so build-sdk/sdk/ohos_arm64/lib/libinit_icu.a +build-sdk/sdk/ohos_arm64/lib/libllvmbackend.so build-sdk/sdk/ohos_arm64/plugins build-sdk/sdk/ohos_arm64/plugins/ecmascript build-sdk/sdk/package.json -- Gitee From e721fddbc270bd7f89990416187cf0338b9a46d9 Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Mon, 11 Nov 2024 14:30:37 +0300 Subject: [PATCH 27/36] Replace undef with poison Signed-off-by: Denis Zavedeev --- static_core/libllvmbackend/transforms/builtins.cpp | 2 +- .../libllvmbackend/transforms/passes/expand_atomics.cpp | 3 +-- .../libllvmbackend/transforms/passes/fixup_poisons.cpp | 9 ++++----- .../libllvmbackend/transforms/passes/gep_propagation.cpp | 9 +++++---- .../transforms/passes/intrinsics_lowering.cpp | 2 +- .../libllvmbackend/transforms/passes/prune_deopt.cpp | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/static_core/libllvmbackend/transforms/builtins.cpp b/static_core/libllvmbackend/transforms/builtins.cpp index 649170a48..6d77eccc5 100644 --- a/static_core/libllvmbackend/transforms/builtins.cpp +++ b/static_core/libllvmbackend/transforms/builtins.cpp @@ -399,7 +399,7 @@ llvm::Value *LowerResolveVirtual(llvm::IRBuilder<> *builder, llvm::CallInst *ins auto method = inst->getFunction()->arg_begin(); auto thiz = inst->getOperand(0U); auto methodId = inst->getOperand(1U); - ASSERT(!llvm::isa(thiz)); + ASSERT(!llvm::isa(thiz)); if (!arkInterface->IsArm64() || !llvm::isa(methodId)) { static constexpr auto ENTRYPOINT_ID = compiler::RuntimeInterface::EntrypointId::RESOLVE_VIRTUAL_CALL_AOT; auto offset = builder->getInt64(0); diff --git a/static_core/libllvmbackend/transforms/passes/expand_atomics.cpp b/static_core/libllvmbackend/transforms/passes/expand_atomics.cpp index d8fa795e5..f0b216e2c 100644 --- a/static_core/libllvmbackend/transforms/passes/expand_atomics.cpp +++ b/static_core/libllvmbackend/transforms/passes/expand_atomics.cpp @@ -44,8 +44,7 @@ llvm::PreservedAnalyses ExpandAtomics::run(llvm::Function &function, } for (auto instruction : instructions) { - bool c = InsertAddrSpaceCast(instruction); - changed |= c; + changed |= InsertAddrSpaceCast(instruction); } } diff --git a/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp b/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp index f61de3db2..033ab24ea 100644 --- a/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp +++ b/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp @@ -18,6 +18,7 @@ #include #include "transforms/gc_utils.h" +#include "transforms/transform_utils.h" #define DEBUG_TYPE "fixup-poisons" @@ -31,15 +32,13 @@ bool FixupPoisons::FixupInstructionOperands(llvm::Instruction &instruction) { bool changed = false; for (auto operand : instruction.operand_values()) { - auto poison = llvm::dyn_cast(operand); + auto poison = llvm::dyn_cast(operand); if (poison == nullptr) { continue; } if (IsGcRefType(poison->getType())) { - LLVM_DEBUG(llvm::dbgs() << "Replacing poison in inst:\n"); - LLVM_DEBUG(instruction.print(llvm::dbgs())); - LLVM_DEBUG(llvm::dbgs() << "with null pointer"); - + ASSERT(llvm::isa(poison) && "Expected poisons only"); + LLVM_DEBUG(llvm::dbgs() << "Replacing poison in inst '" << instruction << "' with null pointer\n"); auto replacement = llvm::Constant::getNullValue(poison->getType()); poison->replaceAllUsesWith(replacement); changed = true; diff --git a/static_core/libllvmbackend/transforms/passes/gep_propagation.cpp b/static_core/libllvmbackend/transforms/passes/gep_propagation.cpp index d87e6127f..d75f88f9d 100644 --- a/static_core/libllvmbackend/transforms/passes/gep_propagation.cpp +++ b/static_core/libllvmbackend/transforms/passes/gep_propagation.cpp @@ -118,8 +118,8 @@ static std::pair FindSplitGep(Function *function, { auto &ctx = function->getContext(); auto bptrTy = llvm::PointerType::get(ctx, ark::llvmbackend::LLVMArkInterface::GC_ADDR_SPACE); - auto undefBase = llvm::UndefValue::get(bptrTy); - auto undefOffset = llvm::UndefValue::get(Type::getInt32Ty(ctx)); + auto undefBase = llvm::PoisonValue::get(bptrTy); + auto undefOffset = llvm::PoisonValue::get(Type::getInt32Ty(ctx)); auto phi = llvm::dyn_cast(inst); Instruction *mbase; Instruction *moff; @@ -172,7 +172,7 @@ void GepPropagation::SplitGepSelectors(Function *function, SmallVectorbegin(), selectors->end(), inst) != selectors->end(); }; ASSERT(std::find_if_not(val->user_begin(), val->user_end(), safeToDelete) == val->user_end()); - val->replaceAllUsesWith(llvm::UndefValue::get(val->getType())); + val->replaceAllUsesWith(llvm::PoisonValue::get(val->getType())); val->eraseFromParent(); } @@ -252,6 +252,7 @@ void GepPropagation::GenerateSelectorInputs(Instruction *inst, const SelectorSpl if (!llvm::isa(mbase->getOperand(i))) { continue; } + ASSERT(llvm::isa(mbase->getOperand(i)) && "Expecting only poisons created in this pass"); auto inPoint = select ? mbase : llvm::cast(inst)->getIncomingBlock(i)->getTerminator(); auto [base, offset] = GenerateInput(input, inst, inPoint, mapping); setInputs(i, base, offset); @@ -267,7 +268,7 @@ Value *GepPropagation::GetConstantOffset(Constant *offset, Type *type) auto offsetRaw = offset->getOperand(0); return llvm::ConstantInt::getSigned(type, llvm::cast(offsetRaw)->getSExtValue()); } - if (offset->isNullValue() || llvm::isa(offset)) { + if (offset->isNullValue() || llvm::isa(offset)) { return llvm::ConstantInt::getNullValue(type); } diff --git a/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.cpp b/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.cpp index c8c4628dc..b03cd09bc 100644 --- a/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.cpp +++ b/static_core/libllvmbackend/transforms/passes/intrinsics_lowering.cpp @@ -145,7 +145,7 @@ bool IntrinsicsLowering::HandleCall(llvm::CallInst *call, LLVMArkInterface::Intr auto callee = GetPandaRuntimeFunctionCallee(intrinsicId, intrinsicFunctionTy, &builder, intrinsicName); if (type->isVectorTy()) { - llvm::Value *vec = llvm::UndefValue::get(type); + llvm::Value *vec = llvm::PoisonValue::get(type); auto vecLen = llvm::cast(type)->getElementCount().getKnownMinValue(); std::vector args; diff --git a/static_core/libllvmbackend/transforms/passes/prune_deopt.cpp b/static_core/libllvmbackend/transforms/passes/prune_deopt.cpp index b9e736ae9..829782b6e 100644 --- a/static_core/libllvmbackend/transforms/passes/prune_deopt.cpp +++ b/static_core/libllvmbackend/transforms/passes/prune_deopt.cpp @@ -198,7 +198,7 @@ void PruneDeopt::MakeUnreachableAfter(BasicBlock *block, Instruction *after) con if (deoptimize && toRemove.isTerminator()) { continue; } - inst->replaceAllUsesWith(llvm::UndefValue::get(inst->getType())); + inst->replaceAllUsesWith(llvm::PoisonValue::get(inst->getType())); inst->eraseFromParent(); } if (!deoptimize) { -- Gitee From 941af090020619ba2b52d525549c6c3b338ef61a Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Tue, 12 Nov 2024 12:34:12 +0300 Subject: [PATCH 28/36] 'setDoesNotThrow' -> 'NoUnwind' Signed-off-by: Denis Zavedeev --- .../libllvmbackend/lowering/gc_barriers.cpp | 4 ++-- .../lowering/llvm_ir_constructor.cpp | 6 +++--- .../libllvmbackend/transforms/builtins.cpp | 19 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/static_core/libllvmbackend/lowering/gc_barriers.cpp b/static_core/libllvmbackend/lowering/gc_barriers.cpp index c2c5c9387..660cd4c34 100644 --- a/static_core/libllvmbackend/lowering/gc_barriers.cpp +++ b/static_core/libllvmbackend/lowering/gc_barriers.cpp @@ -37,14 +37,14 @@ inline llvm::Function *GetOrDeclarePreWrbinterposer(llvm::FunctionType *function auto function = module->getFunction(NAME); if (function != nullptr) { - ASSERT(function->doesNotThrow()); + ASSERT(function->hasFnAttribute(llvm::Attribute::NoUnwind)); ASSERT(function->getVisibility() == llvm::GlobalValue::ProtectedVisibility); ASSERT(function->getCallingConv() == llvm::CallingConv::ArkFast1); return function; } function = llvm::Function::Create(functionType, llvm::Function::ExternalLinkage, NAME, module); - function->setDoesNotThrow(); + function->addFnAttr(llvm::Attribute::NoUnwind); function->setVisibility(llvm::GlobalValue::ProtectedVisibility); function->setSectionPrefix(NAME); function->setCallingConv(llvm::CallingConv::ArkFast1); diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index b542a5086..7f50059ac 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -105,12 +105,12 @@ inline llvm::Function *CreateFunctionDeclaration(llvm::FunctionType *functionTyp auto function = module->getFunction(name); if (function != nullptr) { ASSERT(function->getVisibility() == llvm::GlobalValue::ProtectedVisibility); - ASSERT(function->doesNotThrow()); + ASSERT(function->hasFnAttribute(llvm::Attribute::NoUnwind)); return function; } function = llvm::Function::Create(functionType, llvm::Function::ExternalLinkage, name, module); - function->setDoesNotThrow(); + function->addFnAttr(llvm::Attribute::NoUnwind); function->setVisibility(llvm::GlobalValue::ProtectedVisibility); function->setSectionPrefix(name); @@ -5295,7 +5295,7 @@ void LLVMIrConstructor::ProvideSafepointPoll(llvm::Module *module, LLVMArkInterf auto pollFtype = llvm::FunctionType::get(builder.getVoidTy(), false); auto poll = llvm::Function::Create(pollFtype, llvm::Function::ExternalLinkage, LLVMArkInterface::GC_SAFEPOINT_POLL_NAME, module); - poll->setDoesNotThrow(); + poll->addFnAttr(llvm::Attribute::NoUnwind); // Creating a body auto entry = llvm::BasicBlock::Create(ctx, "bb", poll); diff --git a/static_core/libllvmbackend/transforms/builtins.cpp b/static_core/libllvmbackend/transforms/builtins.cpp index 6d77eccc5..68daa8f79 100644 --- a/static_core/libllvmbackend/transforms/builtins.cpp +++ b/static_core/libllvmbackend/transforms/builtins.cpp @@ -20,7 +20,6 @@ #include "lowering/gc_barriers.h" #include "lowering/metadata.h" -#include "compiler/optimizer/ir/basicblock.h" #include "compiler/optimizer/ir/inst.h" #include @@ -196,8 +195,8 @@ llvm::Function *LenArray(llvm::Module *module) llvm::Type::getInt32Ty(module->getContext())}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, LEN_ARRAY_BUILTIN, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); function->addFnAttr(llvm::Attribute::ReadNone); function->addFnAttr(llvm::Attribute::WillReturn); return function; @@ -214,8 +213,8 @@ llvm::Function *KeepThis(llvm::Module *module) llvm::FunctionType::get(llvm::Type::getVoidTy(module->getContext()), {llvm::PointerType::get(module->getContext(), LLVMArkInterface::GC_ADDR_SPACE)}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, KEEP_THIS_BUILTIN, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); function->addFnAttr(llvm::Attribute::WillReturn); return function; } @@ -229,8 +228,8 @@ llvm::Function *BarrierReturnVoid(llvm::Module *module) auto type = llvm::FunctionType::get(llvm::Type::getVoidTy(module->getContext()), {}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, BARRIER_RETURN_VOID_BUILTIN, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); function->addFnAttr(llvm::Attribute::WillReturn); return function; } @@ -246,8 +245,8 @@ llvm::Function *LoadClass(llvm::Module *module) llvm::PointerType::get(module->getContext(), 0), {llvm::Type::getInt32Ty(module->getContext()), llvm::Type::getInt32Ty(module->getContext())}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, LOAD_CLASS_BUILTIN, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); return function; } @@ -262,8 +261,8 @@ llvm::Function *LoadInitClass(llvm::Module *module) llvm::PointerType::get(module->getContext(), 0), {llvm::Type::getInt32Ty(module->getContext()), llvm::Type::getInt32Ty(module->getContext())}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, LOAD_INIT_CLASS_BUILTIN, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); return function; } @@ -278,8 +277,8 @@ llvm::Function *PreWRB(llvm::Module *module, unsigned addrSpace) auto type = llvm::FunctionType::get(llvm::Type::getVoidTy(ctx), {llvm::PointerType::get(ctx, addrSpace), llvm::Type::getInt1Ty(ctx)}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, builtinName, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); function->addFnAttr(llvm::Attribute::ArgMemOnly); function->addFnAttr(llvm::Attribute::WillReturn); function->addParamAttr(0U, llvm::Attribute::ReadOnly); @@ -299,8 +298,8 @@ llvm::Function *PostWRB(llvm::Module *module, unsigned addrSpace) llvm::PointerType::get(ctx, LLVMArkInterface::GC_ADDR_SPACE)}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, builtinName, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); function->addFnAttr(llvm::Attribute::ArgMemOnly); function->addFnAttr(llvm::Attribute::WillReturn); function->addParamAttr(0U, llvm::Attribute::ReadNone); @@ -319,8 +318,8 @@ llvm::Function *LoadString(llvm::Module *module) llvm::PointerType::get(module->getContext(), LLVMArkInterface::GC_ADDR_SPACE), {llvm::Type::getInt32Ty(module->getContext()), llvm::Type::getInt32Ty(module->getContext())}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, LOAD_STRING_BUILTIN, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); return function; } @@ -336,8 +335,8 @@ llvm::Function *ResolveVirtual(llvm::Module *module) llvm::PointerType::get(module->getContext(), 0)}, false); function = llvm::Function::Create(type, llvm::Function::ExternalLinkage, RESOLVE_VIRTUAL_BUILTIN, module); - function->setDoesNotThrow(); function->setSectionPrefix(BUILTIN_SECTION); + function->addFnAttr(llvm::Attribute::NoUnwind); return function; } -- Gitee From 84cf42ef3d2b6e205905db0b658f8d11819a66ad Mon Sep 17 00:00:00 2001 From: Denis Zavedeev Date: Wed, 13 Nov 2024 16:46:40 +0300 Subject: [PATCH 29/36] Poisons Signed-off-by: Denis Zavedeev --- .../transforms/passes/fixup_poisons.cpp | 14 +++++----- static_core/tests/checked/CMakeLists.txt | 3 ++- .../checked/llvm_stack_overflow_undef.pa | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 static_core/tests/checked/llvm_stack_overflow_undef.pa diff --git a/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp b/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp index 033ab24ea..3b1e02058 100644 --- a/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp +++ b/static_core/libllvmbackend/transforms/passes/fixup_poisons.cpp @@ -18,7 +18,6 @@ #include #include "transforms/gc_utils.h" -#include "transforms/transform_utils.h" #define DEBUG_TYPE "fixup-poisons" @@ -32,15 +31,14 @@ bool FixupPoisons::FixupInstructionOperands(llvm::Instruction &instruction) { bool changed = false; for (auto operand : instruction.operand_values()) { - auto poison = llvm::dyn_cast(operand); - if (poison == nullptr) { + auto undef = llvm::dyn_cast(operand); + if (undef == nullptr) { continue; } - if (IsGcRefType(poison->getType())) { - ASSERT(llvm::isa(poison) && "Expected poisons only"); - LLVM_DEBUG(llvm::dbgs() << "Replacing poison in inst '" << instruction << "' with null pointer\n"); - auto replacement = llvm::Constant::getNullValue(poison->getType()); - poison->replaceAllUsesWith(replacement); + if (IsGcRefType(undef->getType())) { + LLVM_DEBUG(llvm::dbgs() << "Replacing undef/poison in inst '" << instruction << "' with null pointer\n"); + auto replacement = llvm::Constant::getNullValue(undef->getType()); + undef->replaceAllUsesWith(replacement); changed = true; } } diff --git a/static_core/tests/checked/CMakeLists.txt b/static_core/tests/checked/CMakeLists.txt index 2a98fb8fa..7fc5cf0d6 100644 --- a/static_core/tests/checked/CMakeLists.txt +++ b/static_core/tests/checked/CMakeLists.txt @@ -174,7 +174,6 @@ if (PANDA_TARGET_AMD64 OR (PANDA_TARGET_ARM64 AND NOT PANDA_ENABLE_ADDRESS_SANIT panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/verify_aot_tests/verify_aot_test.pa AUX_FILES verify_aot_tests_file1 verify_aot_tests_file2) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/zero_const_in_save_state.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/loop-unroll-constant.pa) - panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm_devirt_external.pa AUX_FILES vcalls_aux.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/memory-coalescing.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/memory-coalescing1.pa) if (PANDA_LLVM_AOT) @@ -187,6 +186,8 @@ if (PANDA_TARGET_AMD64 OR (PANDA_TARGET_ARM64 AND NOT PANDA_ENABLE_ADDRESS_SANIT panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/virtual_to_static.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/memset.pa) + panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm_devirt_external.pa AUX_FILES vcalls_aux.pa) + panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm_stack_overflow_undef.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-optlevel.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-broken-ir.pa) panda_add_checked_test(FILE ${CMAKE_CURRENT_SOURCE_DIR}/llvmaot-gc-intrusion.pa) diff --git a/static_core/tests/checked/llvm_stack_overflow_undef.pa b/static_core/tests/checked/llvm_stack_overflow_undef.pa new file mode 100644 index 000000000..93f6a01e7 --- /dev/null +++ b/static_core/tests/checked/llvm_stack_overflow_undef.pa @@ -0,0 +1,26 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#! CHECKER Should be no undef in LLVM AOT in case of stack overflow +#! RUN_LLVM options: "--llvm-dump-after" +#! READ_FILE "console.out" +#! LLVM_METHOD /define.*\".*myCall.*\"/ +#! INST_NEXT_NOT "ret ptr addrspace(271) undef" + +.record A { +} + +.function A A.myCall(A a0) { + call.short A.myCall, a0 + return.obj +} -- Gitee From 995857b9d70c71e97eb4a35b27fa08d0c420a068 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Fri, 15 Nov 2024 10:43:35 +0300 Subject: [PATCH 30/36] Fix indexOf tail call types Signed-off-by: Roman Zhuykov --- .../plugins/ets/irtoc_scripts/string.irt | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/static_core/plugins/ets/irtoc_scripts/string.irt b/static_core/plugins/ets/irtoc_scripts/string.irt index f52165a55..d8356784d 100644 --- a/static_core/plugins/ets/irtoc_scripts/string.irt +++ b/static_core/plugins/ets/irtoc_scripts/string.irt @@ -1137,7 +1137,7 @@ function(:StringIndexOf, LiveOut(str_data_size_u16).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u16 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_UNCOMPRESSED_SMALL") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedSmall").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedSmall").Terminator.i32 } # 16 <= data size < 32 If(str_data_size_u16, 32).LT.Unlikely.b { @@ -1145,14 +1145,14 @@ function(:StringIndexOf, LiveOut(str_data_size_u16).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u16 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_UNCOMPRESSED_MEDIUM") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedMedium").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedMedium").Terminator.i32 } # 32 <= data size LiveOut(str_data).DstReg(regmap[:arg0]).ptr LiveOut(str_data_size_u16).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u16 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_UNCOMPRESSED") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressed").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressed").Terminator.i32 } IfImm(Compare(ch, Constants::MAX_U8_VALUE).A.b).Imm(0).NE.Unlikely.b { @@ -1166,7 +1166,7 @@ function(:StringIndexOf, LiveOut(str_data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED_SMALL") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedSmall").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedSmall").Terminator.i32 } # 8 <= data size < 16 If(str_data_size_u8, 16).LT.Unlikely.b { @@ -1174,7 +1174,7 @@ function(:StringIndexOf, LiveOut(str_data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED_MEDIUM") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedMedium").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedMedium").Terminator.i32 } # 16 <= data size < 32 If(str_data_size_u8, 32).LT.Unlikely.b { @@ -1182,14 +1182,14 @@ function(:StringIndexOf, LiveOut(str_data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED_LARGE") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedLarge").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedLarge").Terminator.i32 } # 32 <= data size LiveOut(str_data).DstReg(regmap[:arg0]).ptr LiveOut(str_data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressed").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressed").Terminator.i32 } @@ -1237,7 +1237,7 @@ function(:StringIndexOfAfter, LiveOut(data_size_u16).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u16 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_UNCOMPRESSED_SMALL") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedSmall").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedSmall").Terminator.i32 } # 16 <= data size < 32 If(data_size_u16, 32).LT.Unlikely.b { @@ -1245,14 +1245,14 @@ function(:StringIndexOfAfter, LiveOut(data_size_u16).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u16 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_UNCOMPRESSED_MEDIUM") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedMedium").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressedMedium").Terminator.i32 } # 32 <= data size LiveOut(data_ptr_u16).DstReg(regmap[:arg0]).ptr LiveOut(data_size_u16).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u16 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_UNCOMPRESSED") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressed").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfUncompressed").Terminator.i32 } IfImm(Compare(ch, Constants::MAX_U8_VALUE).A.b).Imm(0).NE.Unlikely.b { @@ -1268,7 +1268,7 @@ function(:StringIndexOfAfter, LiveOut(data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED_SMALL") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedSmall").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedSmall").Terminator.i32 } # 8 <= data size < 16 If(data_size_u8, 16).LT.Unlikely.b { @@ -1276,7 +1276,7 @@ function(:StringIndexOfAfter, LiveOut(data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED_MEDIUM") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedMedium").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedMedium").Terminator.i32 } # 16 <= data size < 32 If(data_size_u8, 32).LT.Unlikely.b { @@ -1284,12 +1284,12 @@ function(:StringIndexOfAfter, LiveOut(data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED_LARGE") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedLarge").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressedLarge").Terminator.i32 } # 32 <= data size LiveOut(data_ptr_u8).DstReg(regmap[:arg0]).ptr LiveOut(data_size_u8).DstReg(regmap[:arg1]).u32 LiveOut(ch).DstReg(regmap[:arg2]).u8 entrypoint = get_entrypoint_offset("STRING_INDEX_OF_COMPRESSED") - Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressed").Terminator.b + Intrinsic(:TAIL_CALL).AddImm(entrypoint).MethodAsImm("StringIndexOfCompressed").Terminator.i32 } -- Gitee From 9ce83c75921f73dbd2aea3ef5be9fd314efc8ee5 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Thu, 14 Nov 2024 23:00:22 +0300 Subject: [PATCH 31/36] Try another saving strategy Signed-off-by: Roman Zhuykov --- .../optimizer/code_generator/codegen-inl.h | 9 ++------ .../runtime/arch/aarch64/call_runtime.S | 11 ++++++--- .../compiled_code_to_runtime_bridge_amd64.S | 6 +++-- .../arm/compiled_code_to_runtime_bridge_arm.S | 23 +++++++++++++++++-- 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/static_core/compiler/optimizer/code_generator/codegen-inl.h b/static_core/compiler/optimizer/code_generator/codegen-inl.h index 1d30df939..3daba9167 100644 --- a/static_core/compiler/optimizer/code_generator/codegen-inl.h +++ b/static_core/compiler/optimizer/code_generator/codegen-inl.h @@ -106,8 +106,8 @@ void Codegen::CallEntrypoint(Inst *inst, EntrypointId id, Reg dstReg, RegMask pr // parameter regs: their initial values must be stored by the caller // Other caller regs stored in bridges FillOnlyParameters(&liveRegs, sizeof...(Args), IS_FASTPATH); - - if (IS_FASTPATH && retRegAlive && dstReg.IsValid()) { + // target return reg must be stored too when necessary + if (retRegAlive && dstReg.IsValid()) { Reg retReg = GetTarget().GetReturnReg(dstReg.GetType()); if (dstReg.GetId() != retReg.GetId()) { GetEncoder()->SetRegister(&liveRegs, nullptr, retReg, true); @@ -128,11 +128,6 @@ void Codegen::CallEntrypoint(Inst *inst, EntrypointId id, Reg dstReg, RegMask pr if (dstReg.IsValid()) { ASSERT(dstReg.IsScalar()); Reg retReg = GetTarget().GetReturnReg(dstReg.GetType()); - if (!IS_FASTPATH && retRegAlive && dstReg.GetId() != retReg.GetId() && - (!GetTarget().FirstParamIsReturnReg(retReg.GetType()) || sizeof...(Args) == 0U)) { - GetEncoder()->SetRegister(&liveRegs, nullptr, retReg, true); - } - // We must: // sign extended INT8 and INT16 to INT32 // zero extended UINT8 and UINT16 to UINT32 diff --git a/static_core/runtime/arch/aarch64/call_runtime.S b/static_core/runtime/arch/aarch64/call_runtime.S index e250e5fe2..e8290db93 100644 --- a/static_core/runtime/arch/aarch64/call_runtime.S +++ b/static_core/runtime/arch/aarch64/call_runtime.S @@ -81,12 +81,17 @@ CFI_RESTORE(d8) .endm -.macro SAVE_CALLER_GP_REGS fp_reg, tmp_reg, paramsnum, mode +.macro SAVE_CALLER_GP_REGS fp_reg, tmp_reg, paramsnum, mode, ret_type .if \mode != RUNTIME_MODE_STUB // parameter holding registers are saved by the caller function .ifeq \paramsnum +.ifnc \ret_type,INTEGER stp x0, x1, [\fp_reg, #-CALLER_REG0_OFFSET+8*0] .else + add \tmp_reg, \fp_reg, #-CALLER_REG0_OFFSET + str x1, [\tmp_reg, #8*1] +.endif +.else // paramsnum > 0 .if \mode == RUNTIME_MODE_ODD_SAVED .ifeq \paramsnum-1 add \tmp_reg, \fp_reg, #-CALLER_REG0_OFFSET @@ -114,7 +119,7 @@ .endif .endif // mode == RUNTIME_MODE_ODD_SAVED .endif -.endif // \mode != RUNTIME_MODE_STUB +.endif // mode != RUNTIME_MODE_STUB // Save caller saved regs // first registers are stored by user of this macro or caller which uses them for arguments @@ -236,7 +241,7 @@ SAVE_CALLEE_FP_REGS sp, BRIDGE_FRAME_SIZE .if \mode != RUNTIME_MODE_SLOW_PATH - SAVE_CALLER_GP_REGS fp, lr, \paramsnum, \mode + SAVE_CALLER_GP_REGS fp, lr, \paramsnum, \mode, \ret_type .endif ldr x19, [fp, #(-CFRAME_FLAGS_SLOT * 8)] diff --git a/static_core/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S b/static_core/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S index 6cbeb3b5d..f20efa8e7 100644 --- a/static_core/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S +++ b/static_core/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S @@ -42,8 +42,10 @@ CFI_RESTORE(rbx) .endm -.macro SAVE_CALLER_GP_REGS fp_reg, paramsnum +.macro SAVE_CALLER_GP_REGS fp_reg, paramsnum, ret_type +.ifnc \ret_type,INTEGER movq %rax, (-CALLER_REG0_OFFSET + 0)(%\fp_reg) +.endif .ifle \paramsnum-3 movq %rcx, (-CALLER_REG0_OFFSET + 8)(%\fp_reg) .endif @@ -200,7 +202,7 @@ TYPE_FUNCTION(\name) mov %r13, MANAGED_THREAD_FRAME_OFFSET(%THREAD_REG) .if \mode != RUNTIME_MODE_SLOW_PATH - SAVE_CALLER_GP_REGS rbp, \paramsnum + SAVE_CALLER_GP_REGS rbp, \paramsnum, \ret_type .endif movq (-CFRAME_FLAGS_SLOT * 8)(%rbp), %r12 diff --git a/static_core/runtime/bridge/arch/arm/compiled_code_to_runtime_bridge_arm.S b/static_core/runtime/bridge/arch/arm/compiled_code_to_runtime_bridge_arm.S index e729a9fdc..6bffcfa25 100644 --- a/static_core/runtime/bridge/arch/arm/compiled_code_to_runtime_bridge_arm.S +++ b/static_core/runtime/bridge/arch/arm/compiled_code_to_runtime_bridge_arm.S @@ -65,17 +65,36 @@ CFI_RESTORE(d8) .endm -.macro SAVE_CALLER_GP_REGS fp_reg, tmp_reg, paramsnum +.macro SAVE_CALLER_GP_REGS fp_reg, tmp_reg, paramsnum, ret_type add \tmp_reg, \fp_reg, #-CALLER_REG0_OFFSET+4*4 .ifeq \paramsnum +#ifdef PANDA_TARGET_ARM32_ABI_HARD +.ifnc \ret_type,INTEGER +#else +.ifc \ret_type,VOID +#endif stmdb \tmp_reg, {r0-r3} +.else + stmdb \tmp_reg, {r2-r3} +.endif .endif + .ifeq \paramsnum-1 +#ifdef PANDA_TARGET_ARM32_ABI_HARD +.ifnc \ret_type,INTEGER +#else +.ifc \ret_type,VOID +#endif stmdb \tmp_reg, {r1-r3} +.else + stmdb \tmp_reg, {r2-r3} +.endif .endif + .ifeq \paramsnum-2 stmdb \tmp_reg, {r2-r3} .endif + .ifeq \paramsnum-3 str r3, [\tmp_reg, #-4] .endif @@ -217,7 +236,7 @@ #endif .if \mode != RUNTIME_MODE_SLOW_PATH - SAVE_CALLER_GP_REGS fp, lr, \paramsnum + SAVE_CALLER_GP_REGS fp, lr, \paramsnum, \ret_type .endif #ifndef PANDA_TARGET_ARM32_ABI_SOFT -- Gitee From 2ac9a68ed32faa6b211a477dd4c401c173d78ab5 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Fri, 15 Nov 2024 11:43:25 +0300 Subject: [PATCH 32/36] Delete FirstParamIsReturnReg func --- .../compiler/optimizer/code_generator/target_info.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/static_core/compiler/optimizer/code_generator/target_info.h b/static_core/compiler/optimizer/code_generator/target_info.h index a41c42a43..7c9f24bda 100644 --- a/static_core/compiler/optimizer/code_generator/target_info.h +++ b/static_core/compiler/optimizer/code_generator/target_info.h @@ -462,14 +462,6 @@ public: return RegMask(mask); } - constexpr bool FirstParamIsReturnReg(TypeInfo type) const - { - if (type.IsScalar()) { - return GetReturnRegId() == GetParamRegId(0U); - } - return GetReturnFpRegId() == GetFpParamRegId(0U); - } - // NOTE(msherstennikov): Take into account register size std::string GetRegName(size_t reg, bool isFp) const { -- Gitee From 22fde25facf0ac80ddf9c2b41c947ccdccc45367 Mon Sep 17 00:00:00 2001 From: Leonid Skvortsov Date: Sat, 2 Nov 2024 18:14:44 +0300 Subject: [PATCH 33/36] Merge all FastPath CCs into one --- .../libllvmbackend/llvm_ark_interface.cpp | 7 ++ .../libllvmbackend/lowering/gc_barriers.cpp | 19 +++--- .../lowering/llvm_ir_constructor.cpp | 67 ++++++------------- .../libllvmbackend/transforms/builtins.cpp | 2 +- .../transforms/runtime_calls.cpp | 36 ++++------ static_core/libllvmbackend/utils.cpp | 16 ----- static_core/libllvmbackend/utils.h | 1 - 7 files changed, 51 insertions(+), 97 deletions(-) diff --git a/static_core/libllvmbackend/llvm_ark_interface.cpp b/static_core/libllvmbackend/llvm_ark_interface.cpp index 4ecd8923b..93566ad6b 100644 --- a/static_core/libllvmbackend/llvm_ark_interface.cpp +++ b/static_core/libllvmbackend/llvm_ark_interface.cpp @@ -525,6 +525,13 @@ llvm::FunctionType *LLVMArkInterface::GetOrCreateRuntimeFunctionType(llvm::LLVMC // sanity check ASSERT(callType == RuntimeCallType::ENTRYPOINT); rtFunctionTy = GetEntrypointDeclaration(ctx, module, static_cast(id)); + if (IsArm64() && GetBridgeType(id) == BridgeType::ENTRYPOINT && rtFunctionTy->getNumParams() % 2U != 0) { + // Adjust parameters so we can use ArkFast calling convention without switching to + // OddSaved bridge + std::vector paramsAdj(rtFunctionTy->params()); + paramsAdj.push_back(llvm::Type::getInt64Ty(ctx)); + rtFunctionTy = llvm::FunctionType::get(rtFunctionTy->getReturnType(), paramsAdj, false); + } } ASSERT(rtFunctionTy != nullptr); diff --git a/static_core/libllvmbackend/lowering/gc_barriers.cpp b/static_core/libllvmbackend/lowering/gc_barriers.cpp index 660cd4c34..a40f676e7 100644 --- a/static_core/libllvmbackend/lowering/gc_barriers.cpp +++ b/static_core/libllvmbackend/lowering/gc_barriers.cpp @@ -39,7 +39,7 @@ inline llvm::Function *GetOrDeclarePreWrbinterposer(llvm::FunctionType *function if (function != nullptr) { ASSERT(function->hasFnAttribute(llvm::Attribute::NoUnwind)); ASSERT(function->getVisibility() == llvm::GlobalValue::ProtectedVisibility); - ASSERT(function->getCallingConv() == llvm::CallingConv::ArkFast1); + ASSERT(function->getCallingConv() == llvm::CallingConv::ArkFast); return function; } @@ -47,7 +47,7 @@ inline llvm::Function *GetOrDeclarePreWrbinterposer(llvm::FunctionType *function function->addFnAttr(llvm::Attribute::NoUnwind); function->setVisibility(llvm::GlobalValue::ProtectedVisibility); function->setSectionPrefix(NAME); - function->setCallingConv(llvm::CallingConv::ArkFast1); + function->setCallingConv(llvm::CallingConv::ArkFast); return function; } @@ -71,18 +71,18 @@ void CreatePreWrbCall(llvm::IRBuilder<> *builder, LLVMArkInterface *arkInterface return; } if (frameRegValue != nullptr) { - ASSERT(utils::IsFastPath(func) || !arkInterface->IsArm64()); + ASSERT(func->getCallingConv() == llvm::CallingConv::ArkFast || !arkInterface->IsArm64()); auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType, ptrType, ptrType}, !VAR_ARGS); auto *callee = GetOrDeclarePreWrbinterposer(functionType, module); auto *call = builder->CreateCall(callee, {load, threadRegValue, frameRegValue}); - call->setCallingConv(llvm::CallingConv::ArkFast1); + call->setCallingConv(llvm::CallingConv::ArkFast); return; } ASSERT(arkInterface->IsArm64()); auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType, ptrType}, !VAR_ARGS); auto *callee = GetOrDeclarePreWrbinterposer(functionType, module); auto *call = builder->CreateCall(callee, {load, threadRegValue}); - call->setCallingConv(llvm::CallingConv::ArkFast1); + call->setCallingConv(llvm::CallingConv::ArkFast); } } // namespace @@ -154,14 +154,15 @@ void EmitPostWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, llvm::Value *offs // LLVM AOT, only 3 parameters auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy}, false); auto call = builder->CreateCall(funcTy, callee, {mem, offset, value}); - call->setCallingConv(llvm::CallingConv::ArkFast3); + call->setCallingConv(llvm::CallingConv::ArkFast); return; } if (arkInterface->IsArm64()) { // Arm64 Irtoc, 4 params (add thread) auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy, ptrTy}, false); auto call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr}); - call->setCallingConv(llvm::CallingConv::ArkFast3); + call->setCallingConv(llvm::CallingConv::ArkFast); + call->addParamAttr(3, llvm::Attribute::InReg); return; } // X86_64 Irtoc, 5 params (add thread, fp) @@ -169,7 +170,9 @@ void EmitPostWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, llvm::Value *offs auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy, ptrTy, ptrTy}, false); auto frameRegPtr = builder->CreateIntToPtr(frameRegValue, ptrTy); auto call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr, frameRegPtr}); - call->setCallingConv(llvm::CallingConv::ArkFast3); + call->setCallingConv(llvm::CallingConv::ArkFast); + call->addParamAttr(3, llvm::Attribute::InReg); + call->addParamAttr(4, llvm::Attribute::InReg); } } // namespace ark::llvmbackend::gc_barriers diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index 7f50059ac..30f74405c 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -553,28 +553,6 @@ static DeoptimizeType GetDeoptimizationType(Inst *inst) } } -static llvm::CallingConv::ID GetFastPathCallingConv(uint32_t numArgs) -{ - switch (numArgs) { - case 0U: - return llvm::CallingConv::ArkFast0; - case 1U: - return llvm::CallingConv::ArkFast1; - case 2U: - return llvm::CallingConv::ArkFast2; - case 3U: - return llvm::CallingConv::ArkFast3; - case 4U: - return llvm::CallingConv::ArkFast4; - case 5U: - return llvm::CallingConv::ArkFast5; - case 6U: - return llvm::CallingConv::ArkFast6; - default: - UNREACHABLE(); - } -} - static RuntimeInterface::EntrypointId GetAllocateArrayTlabEntrypoint(size_t elementSize) { switch (elementSize) { @@ -789,13 +767,7 @@ static void CheckSlowPathName(const std::string &name, size_t funcArgsNum, size_ bool LLVMIrConstructor::EmitSlowPathEntry(Inst *inst) { ASSERT(GetGraph()->GetMode().IsFastPath()); - ASSERT(func_->getCallingConv() == llvm::CallingConv::ArkFast0 || - func_->getCallingConv() == llvm::CallingConv::ArkFast1 || - func_->getCallingConv() == llvm::CallingConv::ArkFast2 || - func_->getCallingConv() == llvm::CallingConv::ArkFast3 || - func_->getCallingConv() == llvm::CallingConv::ArkFast4 || - func_->getCallingConv() == llvm::CallingConv::ArkFast5 || - func_->getCallingConv() == llvm::CallingConv::ArkFast6); + ASSERT(func_->getCallingConv() == llvm::CallingConv::ArkFast); // Arguments ArenaVector args(GetGraph()->GetLocalAllocator()->Adapter()); @@ -823,10 +795,12 @@ bool LLVMIrConstructor::EmitSlowPathEntry(Inst *inst) argTypes.push_back(builder_.getPtrTy()); auto ftype = llvm::FunctionType::get(GetType(inst->GetType()), argTypes, false); callee = llvm::Function::Create(ftype, llvm::Function::ExternalLinkage, externalName, func_->getParent()); - callee->setCallingConv(GetFastPathCallingConv(inst->GetInputs().Size())); + callee->setCallingConv(llvm::CallingConv::ArkFast); } auto call = builder_.CreateCall(callee->getFunctionType(), callee, args); + call->addParamAttr(callee->arg_size() - 1U, llvm::Attribute::InReg); + call->addParamAttr(callee->arg_size() - 2U, llvm::Attribute::InReg); call->setCallingConv(callee->getCallingConv()); call->setTailCallKind(llvm::CallInst::TailCallKind::TCK_MustTail); call->addFnAttr(llvm::Attribute::get(call->getContext(), "ark-tail-call")); @@ -929,13 +903,7 @@ bool LLVMIrConstructor::EmitInterpreterReturn([[maybe_unused]] Inst *inst) bool LLVMIrConstructor::EmitTailCall(Inst *inst) { - ASSERT(func_->getCallingConv() == llvm::CallingConv::ArkFast0 || - func_->getCallingConv() == llvm::CallingConv::ArkFast1 || - func_->getCallingConv() == llvm::CallingConv::ArkFast2 || - func_->getCallingConv() == llvm::CallingConv::ArkFast3 || - func_->getCallingConv() == llvm::CallingConv::ArkFast4 || - func_->getCallingConv() == llvm::CallingConv::ArkFast5 || - func_->getCallingConv() == llvm::CallingConv::ArkFast6 || + ASSERT(func_->getCallingConv() == llvm::CallingConv::ArkFast || func_->getCallingConv() == llvm::CallingConv::ArkInt); llvm::CallInst *call; @@ -1157,7 +1125,7 @@ bool LLVMIrConstructor::EmitStringGetCharsTlab(Inst *inst) auto result = CreateEntrypointCall(eid, inst, {GetInputValue(inst, 0), GetInputValue(inst, 1), GetInputValue(inst, 2), klass}); ASSERT(result->getCallingConv() == llvm::CallingConv::C); - result->setCallingConv(llvm::CallingConv::ArkFast4); + result->setCallingConv(llvm::CallingConv::ArkFast); result->addRetAttr(llvm::Attribute::NonNull); result->addRetAttr(llvm::Attribute::NoAlias); ValueMapAdd(inst, result); @@ -1183,7 +1151,7 @@ bool LLVMIrConstructor::EmitStringHashCode(Inst *inst) auto newHash = CreateEntrypointCall(RuntimeInterface::EntrypointId::STRING_HASH_CODE_COMPRESSED, inst, {string}); ASSERT(newHash->getCallingConv() == llvm::CallingConv::C); - newHash->setCallingConv(llvm::CallingConv::ArkFast1); + newHash->setCallingConv(llvm::CallingConv::ArkFast); builder_.CreateBr(continuation); SetCurrentBasicBlock(continuation); @@ -1481,7 +1449,7 @@ llvm::CallInst *LLVMIrConstructor::CreateFastPathCall(Inst *inst, RuntimeInterfa { auto call = CreateEntrypointCall(eid, inst, args); ASSERT(call->getCallingConv() == llvm::CallingConv::C); - call->setCallingConv(GetFastPathCallingConv(args.size())); + call->setCallingConv(llvm::CallingConv::ArkFast); return call; } @@ -2171,12 +2139,10 @@ llvm::Value *LLVMIrConstructor::CreateNewStringFromCharsTlab(Inst *inst, llvm::V { auto entryId = RuntimeInterface::EntrypointId::CREATE_STRING_FROM_CHAR_ARRAY_TLAB_COMPRESSED; ArenaVector arguments(GetGraph()->GetLocalAllocator()->Adapter()); - auto callConv = llvm::CallingConv::ArkFast3; if (llvm::isa(offset) && llvm::cast(offset)->isNullValue()) { entryId = RuntimeInterface::EntrypointId::CREATE_STRING_FROM_ZERO_BASED_CHAR_ARRAY_TLAB_COMPRESSED; } else { arguments.push_back(offset); - callConv = llvm::CallingConv::ArkFast4; } arguments.push_back(length); arguments.push_back(array); @@ -2185,7 +2151,7 @@ llvm::Value *LLVMIrConstructor::CreateNewStringFromCharsTlab(Inst *inst, llvm::V arguments.push_back(klass); auto result = CreateEntrypointCall(entryId, inst, arguments); ASSERT(result->getCallingConv() == llvm::CallingConv::C); - result->setCallingConv(callConv); + result->setCallingConv(llvm::CallingConv::ArkFast); MarkAsAllocation(result); return result; } @@ -2195,7 +2161,7 @@ llvm::Value *LLVMIrConstructor::CreateNewStringFromStringTlab(Inst *inst, llvm:: auto entryId = RuntimeInterface::EntrypointId::CREATE_STRING_FROM_STRING_TLAB_COMPRESSED; auto result = CreateEntrypointCall(entryId, inst, {stringVal}); ASSERT(result->getCallingConv() == llvm::CallingConv::C); - result->setCallingConv(llvm::CallingConv::ArkFast1); + result->setCallingConv(llvm::CallingConv::ArkFast); MarkAsAllocation(result); return result; } @@ -2578,6 +2544,8 @@ llvm::CallInst *LLVMIrConstructor::CreateTailCallFastPath(Inst *inst) cc = callee->getCallingConv(); } auto call = builder_.CreateCall(callee->getFunctionType(), callee, args); + call->addParamAttr(callee->arg_size() - 1U, llvm::Attribute::InReg); + call->addParamAttr(callee->arg_size() - 2U, llvm::Attribute::InReg); call->setCallingConv(cc); return call; } @@ -4752,7 +4720,7 @@ void LLVMIrConstructor::VisitMonitor(GraphVisitor *v, Inst *inst) : RuntimeInterface::EntrypointId::MONITOR_EXIT_FAST_PATH; auto call = ctor->CreateEntrypointCall(eid, inst, {object}); ASSERT(call->getCallingConv() == llvm::CallingConv::C); - call->setCallingConv(llvm::CallingConv::ArkFast1); + call->setCallingConv(llvm::CallingConv::ArkFast); } void LLVMIrConstructor::VisitSqrt(GraphVisitor *v, Inst *inst) @@ -5132,7 +5100,7 @@ LLVMIrConstructor::LLVMIrConstructor(Graph *graph, llvm::Module *module, llvm::L cc_.push_back(i); } // Get calling convention excluding thread and frame registers - callingConv = GetFastPathCallingConv(cc_.size()); + callingConv = llvm::CallingConv::ArkFast; cc_.push_back(GetThreadReg(Arch::AARCH64)); cc_.push_back(AARCH64_REAL_FP); } @@ -5146,7 +5114,8 @@ LLVMIrConstructor::LLVMIrConstructor(Graph *graph, llvm::Module *module, llvm::L func_->setCallingConv(callingConv); // Scenario of code generation for FastPath having zero arguments and return value is not tested - ASSERT(callingConv != llvm::CallingConv::ArkFast0 || func_->getReturnType()->isVoidTy()); + // With unified calling convention it should not be an issue, but keep this assert anyway + ASSERT(callingConv != llvm::CallingConv::ArkFast || !cc_.empty() || func_->getReturnType()->isVoidTy()); if (graph->SupportManagedCode()) { func_->setGC(std::string {llvmbackend::LLVMArkInterface::GC_STRATEGY}); @@ -5156,6 +5125,10 @@ LLVMIrConstructor::LLVMIrConstructor(Graph *graph, llvm::Module *module, llvm::L auto klassIdMd = llvm::ConstantAsMetadata::get(builder_.getInt32(klassId)); func_->addMetadata(llvmbackend::LLVMArkInterface::FUNCTION_MD_CLASS_ID, *llvm::MDNode::get(*context, {klassIdMd})); + if (graph->GetMode().IsFastPath()) { + func_->addParamAttr(func_->arg_size() - 1, llvm::Attribute::InReg); + func_->addParamAttr(func_->arg_size() - 2, llvm::Attribute::InReg); + } if (!arkInterface_->IsIrtocMode()) { func_->addMetadata("use-ark-frame", *llvm::MDNode::get(*context, {})); } diff --git a/static_core/libllvmbackend/transforms/builtins.cpp b/static_core/libllvmbackend/transforms/builtins.cpp index 68daa8f79..44174b749 100644 --- a/static_core/libllvmbackend/transforms/builtins.cpp +++ b/static_core/libllvmbackend/transforms/builtins.cpp @@ -410,7 +410,7 @@ llvm::Value *LowerResolveVirtual(llvm::IRBuilder<> *builder, llvm::CallInst *ins entrypointAddress = CreateEntrypointCallHelper(builder, ENTRYPOINT_ID, {method, thiz, methodId, offset}, arkInterface, inst); ASSERT(entrypointAddress->getCallingConv() == llvm::CallingConv::C); - entrypointAddress->setCallingConv(llvm::CallingConv::ArkFast4); + entrypointAddress->setCallingConv(llvm::CallingConv::ArkFast); } return builder->CreateIntToPtr(entrypointAddress, builder->getPtrTy()); diff --git a/static_core/libllvmbackend/transforms/runtime_calls.cpp b/static_core/libllvmbackend/transforms/runtime_calls.cpp index b2144a26e..2dd278206 100644 --- a/static_core/libllvmbackend/transforms/runtime_calls.cpp +++ b/static_core/libllvmbackend/transforms/runtime_calls.cpp @@ -59,37 +59,25 @@ llvm::CallInst *CreateEntrypointCallCommon(llvm::IRBuilder<> *builder, llvm::Val auto threadRegPtr = builder->CreateIntToPtr(threadRegValue, builder->getPtrTy()); auto addr = builder->CreateConstInBoundsGEP1_64(builder->getInt8Ty(), threadRegPtr, tlsOffset); auto callee = builder->CreateLoad(builder->getPtrTy(), addr, functionName + "_addr"); + auto bridgeType = arkInterface->GetBridgeType(eid); auto calleeFuncTy = llvm::cast(functionProto); - auto call = builder->CreateCall(calleeFuncTy, callee, arguments, bundle); + llvm::CallInst *call; + if (arkInterface->IsArm64() && bridgeType == BridgeType::ENTRYPOINT && + calleeFuncTy->getNumParams() > arguments.size()) { + std::vector argsAdj(arguments); + argsAdj.push_back(llvm::UndefValue::get(builder->getInt64Ty())); + call = builder->CreateCall(calleeFuncTy, callee, argsAdj, bundle); + } else { + call = builder->CreateCall(calleeFuncTy, callee, arguments, bundle); + } - auto bridgeType = arkInterface->GetBridgeType(eid); ASSERT(bridgeType != BridgeType::SLOW_PATH && bridgeType != BridgeType::ODD_SAVED); ASSERT(call->getCallingConv() == llvm::CallingConv::C); - // Entrypoint bridges preserve a lot of registers, so we can put appropriate ArkFast convention for them. + // Entrypoint bridges preserve a lot of registers, so we can put ArkFast convention for them. if (bridgeType == BridgeType::ENTRYPOINT) { - llvm::CallingConv::ID cc = llvm::CallingConv::C; - switch (arguments.size()) { - case 0U: - cc = llvm::CallingConv::ArkFast0; - break; - case 1U: - case 2U: - cc = llvm::CallingConv::ArkFast2; - break; - case 3U: - case 4U: - cc = llvm::CallingConv::ArkFast4; - break; - case 5U: - case 6U: - cc = llvm::CallingConv::ArkFast6; - break; - default: - llvm_unreachable("Entrypoints with 7 and more arguments are not supported"); - } - call->setCallingConv(cc); + call->setCallingConv(llvm::CallingConv::ArkFast); } return call; diff --git a/static_core/libllvmbackend/utils.cpp b/static_core/libllvmbackend/utils.cpp index 6a52bdeb9..dc58a6314 100644 --- a/static_core/libllvmbackend/utils.cpp +++ b/static_core/libllvmbackend/utils.cpp @@ -89,20 +89,4 @@ llvm::Value *CreateLoadMethodUsingVTable(llvm::Value *thiz, llvm::Function *call return builder->CreateLoad(builder->getPtrTy(), methodPtr); } -bool IsFastPath(llvm::Function *func) -{ - switch (func->getCallingConv()) { - case llvm::CallingConv::ArkFast0: - case llvm::CallingConv::ArkFast1: - case llvm::CallingConv::ArkFast2: - case llvm::CallingConv::ArkFast3: - case llvm::CallingConv::ArkFast4: - case llvm::CallingConv::ArkFast5: - case llvm::CallingConv::ArkFast6: - return true; - default: - return false; - } -} - } // namespace ark::llvmbackend::utils diff --git a/static_core/libllvmbackend/utils.h b/static_core/libllvmbackend/utils.h index 0192e8f45..f63ce60c4 100644 --- a/static_core/libllvmbackend/utils.h +++ b/static_core/libllvmbackend/utils.h @@ -30,7 +30,6 @@ llvm::Value *CreateLoadClassFromObject(llvm::Value *object, llvm::IRBuilder<> *b ark::llvmbackend::LLVMArkInterface *arkInterface); llvm::Value *CreateLoadMethodUsingVTable(llvm::Value *thiz, llvm::Function *caller, size_t methodId, llvm::IRBuilder<> *builder, LLVMArkInterface *arkInterface); -bool IsFastPath(llvm::Function *func); } // namespace ark::llvmbackend::utils -- Gitee From 5db3cd1c3b2d58856ff1b3e6d150413b2593e6c0 Mon Sep 17 00:00:00 2001 From: Leonid Skvortsov Date: Fri, 8 Nov 2024 11:10:34 +0300 Subject: [PATCH 34/36] Fix magic numbers --- static_core/libllvmbackend/lowering/gc_barriers.cpp | 6 +++--- static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/static_core/libllvmbackend/lowering/gc_barriers.cpp b/static_core/libllvmbackend/lowering/gc_barriers.cpp index a40f676e7..1a2b86f12 100644 --- a/static_core/libllvmbackend/lowering/gc_barriers.cpp +++ b/static_core/libllvmbackend/lowering/gc_barriers.cpp @@ -162,7 +162,7 @@ void EmitPostWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, llvm::Value *offs auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy, ptrTy}, false); auto call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr}); call->setCallingConv(llvm::CallingConv::ArkFast); - call->addParamAttr(3, llvm::Attribute::InReg); + call->addParamAttr(3U, llvm::Attribute::InReg); return; } // X86_64 Irtoc, 5 params (add thread, fp) @@ -171,8 +171,8 @@ void EmitPostWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, llvm::Value *offs auto frameRegPtr = builder->CreateIntToPtr(frameRegValue, ptrTy); auto call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr, frameRegPtr}); call->setCallingConv(llvm::CallingConv::ArkFast); - call->addParamAttr(3, llvm::Attribute::InReg); - call->addParamAttr(4, llvm::Attribute::InReg); + call->addParamAttr(3U, llvm::Attribute::InReg); + call->addParamAttr(4U, llvm::Attribute::InReg); } } // namespace ark::llvmbackend::gc_barriers diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index 30f74405c..5faf9344b 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -5126,8 +5126,8 @@ LLVMIrConstructor::LLVMIrConstructor(Graph *graph, llvm::Module *module, llvm::L func_->addMetadata(llvmbackend::LLVMArkInterface::FUNCTION_MD_CLASS_ID, *llvm::MDNode::get(*context, {klassIdMd})); if (graph->GetMode().IsFastPath()) { - func_->addParamAttr(func_->arg_size() - 1, llvm::Attribute::InReg); - func_->addParamAttr(func_->arg_size() - 2, llvm::Attribute::InReg); + func_->addParamAttr(func_->arg_size() - 1U, llvm::Attribute::InReg); + func_->addParamAttr(func_->arg_size() - 2U, llvm::Attribute::InReg); } if (!arkInterface_->IsIrtocMode()) { func_->addMetadata("use-ark-frame", *llvm::MDNode::get(*context, {})); -- Gitee From 53c1e93a26f21880f7646593700a696e3d45a343 Mon Sep 17 00:00:00 2001 From: Leonid Skvortsov Date: Mon, 11 Nov 2024 15:55:44 +0300 Subject: [PATCH 35/36] Use poison --- static_core/libllvmbackend/transforms/runtime_calls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static_core/libllvmbackend/transforms/runtime_calls.cpp b/static_core/libllvmbackend/transforms/runtime_calls.cpp index 2dd278206..538366ba1 100644 --- a/static_core/libllvmbackend/transforms/runtime_calls.cpp +++ b/static_core/libllvmbackend/transforms/runtime_calls.cpp @@ -66,7 +66,7 @@ llvm::CallInst *CreateEntrypointCallCommon(llvm::IRBuilder<> *builder, llvm::Val if (arkInterface->IsArm64() && bridgeType == BridgeType::ENTRYPOINT && calleeFuncTy->getNumParams() > arguments.size()) { std::vector argsAdj(arguments); - argsAdj.push_back(llvm::UndefValue::get(builder->getInt64Ty())); + argsAdj.push_back(llvm::PoisonValue::get(builder->getInt64Ty())); call = builder->CreateCall(calleeFuncTy, callee, argsAdj, bundle); } else { call = builder->CreateCall(calleeFuncTy, callee, arguments, bundle); -- Gitee From 703fdf4f4ce6604fee68d90fe6a28532ee832051 Mon Sep 17 00:00:00 2001 From: Roman Zhuykov Date: Fri, 8 Nov 2024 17:59:37 +0300 Subject: [PATCH 36/36] Fix PreWrb and cosmetics --- .../libllvmbackend/llvm_ark_interface.cpp | 10 +-- .../libllvmbackend/lowering/gc_barriers.cpp | 63 +++++++++---------- .../lowering/llvm_ir_constructor.cpp | 17 +++-- .../transforms/runtime_calls.cpp | 29 +++++---- 4 files changed, 57 insertions(+), 62 deletions(-) diff --git a/static_core/libllvmbackend/llvm_ark_interface.cpp b/static_core/libllvmbackend/llvm_ark_interface.cpp index 93566ad6b..083b79a49 100644 --- a/static_core/libllvmbackend/llvm_ark_interface.cpp +++ b/static_core/libllvmbackend/llvm_ark_interface.cpp @@ -521,20 +521,22 @@ llvm::FunctionType *LLVMArkInterface::GetOrCreateRuntimeFunctionType(llvm::LLVMC if (callType == RuntimeCallType::INTRINSIC) { rtFunctionTy = GetIntrinsicDeclaration(ctx, static_cast(id)); + ASSERT(rtFunctionTy != nullptr); } else { - // sanity check ASSERT(callType == RuntimeCallType::ENTRYPOINT); rtFunctionTy = GetEntrypointDeclaration(ctx, module, static_cast(id)); + ASSERT(rtFunctionTy != nullptr); + + // Entrypoint bridge on arm64 rounds up the amount of parameters to the next even number, + // and we are following that scheme to make it possible to use ArkFast convention. + // Otherwise, we have to switch to creating OddSaved bridges for each entrypoint. if (IsArm64() && GetBridgeType(id) == BridgeType::ENTRYPOINT && rtFunctionTy->getNumParams() % 2U != 0) { - // Adjust parameters so we can use ArkFast calling convention without switching to - // OddSaved bridge std::vector paramsAdj(rtFunctionTy->params()); paramsAdj.push_back(llvm::Type::getInt64Ty(ctx)); rtFunctionTy = llvm::FunctionType::get(rtFunctionTy->getReturnType(), paramsAdj, false); } } - ASSERT(rtFunctionTy != nullptr); runtimeFunctionTypes_.insert({rtFunctionName, rtFunctionTy}); return rtFunctionTy; } diff --git a/static_core/libllvmbackend/lowering/gc_barriers.cpp b/static_core/libllvmbackend/lowering/gc_barriers.cpp index 1a2b86f12..bb45e509f 100644 --- a/static_core/libllvmbackend/lowering/gc_barriers.cpp +++ b/static_core/libllvmbackend/lowering/gc_barriers.cpp @@ -29,7 +29,7 @@ namespace ark::llvmbackend::gc_barriers { namespace { -inline llvm::Function *GetOrDeclarePreWrbinterposer(llvm::FunctionType *functionType, llvm::Module *module) +inline llvm::Function *GetOrDeclarePreWrbInterposer(llvm::FunctionType *functionType, llvm::Module *module) { ASSERT(functionType != nullptr); ASSERT(module != nullptr); @@ -61,27 +61,28 @@ void CreatePreWrbCall(llvm::IRBuilder<> *builder, LLVMArkInterface *arkInterface auto *ptrType = builder->getPtrTy(); auto *ptrGcType = builder->getPtrTy(LLVMArkInterface::GC_ADDR_SPACE); auto *voidType = builder->getVoidTy(); + llvm::CallInst *call; - if (!arkInterface->IsIrtocMode()) { - // AoT mode, call PreWrbEntrypoint + if (!arkInterface->IsIrtocMode()) { // LLVM AOT, call PreWrbEntrypoint with 1 parameter ASSERT(frameRegValue == nullptr); auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType}, !VAR_ARGS); - [[maybe_unused]] auto *call = builder->CreateCall(functionType, entrypoint, {load}); - ASSERT(call->getCallingConv() == llvm::CallingConv::C); + builder->CreateCall(functionType, entrypoint, {load}); return; } - if (frameRegValue != nullptr) { + + if (frameRegValue == nullptr) { // Arm64 Irtoc interpreter, call interposer with 2 parameters (add thread) + ASSERT(func->getCallingConv() == llvm::CallingConv::ArkInt && arkInterface->IsArm64()); + auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType, ptrType}, !VAR_ARGS); + auto *callee = GetOrDeclarePreWrbInterposer(functionType, module); + call = builder->CreateCall(callee, {load, threadRegValue}); + } else { // Otherwise, call interposer with 3 parameters (add thread, fp) ASSERT(func->getCallingConv() == llvm::CallingConv::ArkFast || !arkInterface->IsArm64()); auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType, ptrType, ptrType}, !VAR_ARGS); - auto *callee = GetOrDeclarePreWrbinterposer(functionType, module); - auto *call = builder->CreateCall(callee, {load, threadRegValue, frameRegValue}); - call->setCallingConv(llvm::CallingConv::ArkFast); - return; + auto *callee = GetOrDeclarePreWrbInterposer(functionType, module); + call = builder->CreateCall(callee, {load, threadRegValue, frameRegValue}); + call->addParamAttr(2U, llvm::Attribute::InReg); } - ASSERT(arkInterface->IsArm64()); - auto *functionType = llvm::FunctionType::get(voidType, {ptrGcType, ptrType}, !VAR_ARGS); - auto *callee = GetOrDeclarePreWrbinterposer(functionType, module); - auto *call = builder->CreateCall(callee, {load, threadRegValue}); + call->addParamAttr(1U, llvm::Attribute::InReg); call->setCallingConv(llvm::CallingConv::ArkFast); } } // namespace @@ -126,7 +127,7 @@ void EmitPreWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, bool isVolatileMem auto objectIsNull = builder->CreateIsNotNull(load); builder->CreateCondBr(objectIsNull, callRuntimeBb, outBb); - // Call Runtime + // Call runtime or interposer builder->SetInsertPoint(callRuntimeBb); CreatePreWrbCall(builder, arkInterface, threadRegValue, frameRegValue, entrypoint, load); builder->CreateBr(outBb); @@ -145,34 +146,28 @@ void EmitPostWRB(llvm::IRBuilder<> *builder, llvm::Value *mem, llvm::Value *offs auto threadRegPtr = builder->CreateIntToPtr(threadRegValue, ptrTy); auto addr = builder->CreateConstInBoundsGEP1_64(builder->getInt8Ty(), threadRegPtr, tlsOffset); auto callee = builder->CreateLoad(ptrTy, addr, "post_wrb_one_object_addr"); + llvm::CallInst *call; - ASSERT(mem->getType()->isPointerTy()); - ASSERT(value->getType()->isPointerTy() && - value->getType()->getPointerAddressSpace() == LLVMArkInterface::GC_ADDR_SPACE); + ASSERT(memTy->isPointerTy() && value->getType() == gcPtrTy); - if (!arkInterface->IsIrtocMode()) { - // LLVM AOT, only 3 parameters + if (!arkInterface->IsIrtocMode()) { // LLVM AOT, only 3 parameters auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy}, false); - auto call = builder->CreateCall(funcTy, callee, {mem, offset, value}); + call = builder->CreateCall(funcTy, callee, {mem, offset, value}); call->setCallingConv(llvm::CallingConv::ArkFast); return; } - if (arkInterface->IsArm64()) { - // Arm64 Irtoc, 4 params (add thread) + if (arkInterface->IsArm64()) { // Arm64 Irtoc, 4 parameters (add thread) auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy, ptrTy}, false); - auto call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr}); - call->setCallingConv(llvm::CallingConv::ArkFast); - call->addParamAttr(3U, llvm::Attribute::InReg); - return; + call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr}); + } else { // X86_64 Irtoc, 5 parameters (add thread, fp) + ASSERT(frameRegValue != nullptr); + auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy, ptrTy, ptrTy}, false); + auto frameRegPtr = builder->CreateIntToPtr(frameRegValue, ptrTy); + call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr, frameRegPtr}); + call->addParamAttr(4U, llvm::Attribute::InReg); } - // X86_64 Irtoc, 5 params (add thread, fp) - ASSERT(frameRegValue != nullptr); - auto funcTy = llvm::FunctionType::get(builder->getVoidTy(), {memTy, int32Ty, gcPtrTy, ptrTy, ptrTy}, false); - auto frameRegPtr = builder->CreateIntToPtr(frameRegValue, ptrTy); - auto call = builder->CreateCall(funcTy, callee, {mem, offset, value, threadRegPtr, frameRegPtr}); - call->setCallingConv(llvm::CallingConv::ArkFast); call->addParamAttr(3U, llvm::Attribute::InReg); - call->addParamAttr(4U, llvm::Attribute::InReg); + call->setCallingConv(llvm::CallingConv::ArkFast); } } // namespace ark::llvmbackend::gc_barriers diff --git a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp index 5faf9344b..786b77dc3 100644 --- a/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp +++ b/static_core/libllvmbackend/lowering/llvm_ir_constructor.cpp @@ -5099,10 +5099,9 @@ LLVMIrConstructor::LLVMIrConstructor(Graph *graph, llvm::Module *module, llvm::L for (size_t i = 0; i < graph->GetRuntime()->GetMethodTotalArgumentsCount(graph->GetMethod()); i++) { cc_.push_back(i); } - // Get calling convention excluding thread and frame registers - callingConv = llvm::CallingConv::ArkFast; cc_.push_back(GetThreadReg(Arch::AARCH64)); cc_.push_back(AARCH64_REAL_FP); + callingConv = llvm::CallingConv::ArkFast; } ccValues_.assign(cc_.size(), nullptr); @@ -5113,9 +5112,13 @@ LLVMIrConstructor::LLVMIrConstructor(Graph *graph, llvm::Module *module, llvm::L ASSERT(func_->getCallingConv() == llvm::CallingConv::C); func_->setCallingConv(callingConv); - // Scenario of code generation for FastPath having zero arguments and return value is not tested - // With unified calling convention it should not be an issue, but keep this assert anyway - ASSERT(callingConv != llvm::CallingConv::ArkFast || !cc_.empty() || func_->getReturnType()->isVoidTy()); + // FastPath having zero real arguments (excluding frame and thread) and return value scenario was not tested + ASSERT(callingConv != llvm::CallingConv::ArkFast || cc_.size() > 2U || func_->getReturnType()->isVoidTy()); + + if (graph->GetMode().IsFastPath()) { + func_->addParamAttr(func_->arg_size() - 1U, llvm::Attribute::InReg); + func_->addParamAttr(func_->arg_size() - 2U, llvm::Attribute::InReg); + } if (graph->SupportManagedCode()) { func_->setGC(std::string {llvmbackend::LLVMArkInterface::GC_STRATEGY}); @@ -5125,10 +5128,6 @@ LLVMIrConstructor::LLVMIrConstructor(Graph *graph, llvm::Module *module, llvm::L auto klassIdMd = llvm::ConstantAsMetadata::get(builder_.getInt32(klassId)); func_->addMetadata(llvmbackend::LLVMArkInterface::FUNCTION_MD_CLASS_ID, *llvm::MDNode::get(*context, {klassIdMd})); - if (graph->GetMode().IsFastPath()) { - func_->addParamAttr(func_->arg_size() - 1U, llvm::Attribute::InReg); - func_->addParamAttr(func_->arg_size() - 2U, llvm::Attribute::InReg); - } if (!arkInterface_->IsIrtocMode()) { func_->addMetadata("use-ark-frame", *llvm::MDNode::get(*context, {})); } diff --git a/static_core/libllvmbackend/transforms/runtime_calls.cpp b/static_core/libllvmbackend/transforms/runtime_calls.cpp index 538366ba1..e6647c6f9 100644 --- a/static_core/libllvmbackend/transforms/runtime_calls.cpp +++ b/static_core/libllvmbackend/transforms/runtime_calls.cpp @@ -55,32 +55,31 @@ llvm::CallInst *CreateEntrypointCallCommon(llvm::IRBuilder<> *builder, llvm::Val ASSERT(arkInterface->DeoptsEnabled() || bundle.empty()); auto tlsOffset = arkInterface->GetEntrypointTlsOffset(eid); auto [functionProto, functionName] = arkInterface->GetEntrypointCallee(eid); + auto calleeFuncTy = llvm::cast(functionProto); auto threadRegPtr = builder->CreateIntToPtr(threadRegValue, builder->getPtrTy()); auto addr = builder->CreateConstInBoundsGEP1_64(builder->getInt8Ty(), threadRegPtr, tlsOffset); auto callee = builder->CreateLoad(builder->getPtrTy(), addr, functionName + "_addr"); auto bridgeType = arkInterface->GetBridgeType(eid); - - auto calleeFuncTy = llvm::cast(functionProto); - llvm::CallInst *call; - if (arkInterface->IsArm64() && bridgeType == BridgeType::ENTRYPOINT && - calleeFuncTy->getNumParams() > arguments.size()) { - std::vector argsAdj(arguments); - argsAdj.push_back(llvm::PoisonValue::get(builder->getInt64Ty())); - call = builder->CreateCall(calleeFuncTy, callee, argsAdj, bundle); - } else { - call = builder->CreateCall(calleeFuncTy, callee, arguments, bundle); - } - ASSERT(bridgeType != BridgeType::SLOW_PATH && bridgeType != BridgeType::ODD_SAVED); - ASSERT(call->getCallingConv() == llvm::CallingConv::C); - // Entrypoint bridges preserve a lot of registers, so we can put ArkFast convention for them. + // Entrypoint bridge preserves a lot of registers, use ArkFast convention for calls. if (bridgeType == BridgeType::ENTRYPOINT) { + llvm::CallInst *call; + // See LLVMArkInterface::GetOrCreateRuntimeFunctionType + if (arkInterface->IsArm64() && calleeFuncTy->getNumParams() > arguments.size()) { + ASSERT(calleeFuncTy->getNumParams() % 2U == 0 && calleeFuncTy->getNumParams() == arguments.size() + 1U); + std::vector argsAdj(arguments); + argsAdj.push_back(llvm::PoisonValue::get(builder->getInt64Ty())); + call = builder->CreateCall(calleeFuncTy, callee, argsAdj, bundle); + } else { + call = builder->CreateCall(calleeFuncTy, callee, arguments, bundle); + } call->setCallingConv(llvm::CallingConv::ArkFast); + return call; } - return call; + return builder->CreateCall(calleeFuncTy, callee, arguments, bundle); } llvm::Value *GetThreadRegValue(llvm::IRBuilder<> *builder, LLVMArkInterface *arkInterface) -- Gitee