From: Weining Lu Date: Wed, 8 Feb 2023 01:07:01 +0000 (+0800) Subject: [flang] Add LoongArch64 support to lib/Optimizer/CodeGen/Target.cpp X-Git-Tag: upstream/17.0.6~18241 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=720f728d4f9f7863101844d6c30c645fb58a4986;p=platform%2Fupstream%2Fllvm.git [flang] Add LoongArch64 support to lib/Optimizer/CodeGen/Target.cpp Add LoongArch64 linux target specifics to Target.cpp which is similar to RISCV-64 in D136547. For LoongArch, a complex floating-point number, or a structure containing just one complex floating-point number, is passed as though it were a structure containing two floating-point reals. Reviewed By: vzakhari Differential Revision: https://reviews.llvm.org/D143131 --- diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp index 7008088..e2d30b0 100644 --- a/flang/lib/Optimizer/CodeGen/Target.cpp +++ b/flang/lib/Optimizer/CodeGen/Target.cpp @@ -492,6 +492,50 @@ struct TargetAMDGPU : public GenericTarget { }; } // namespace +//===----------------------------------------------------------------------===// +// LoongArch64 linux target specifics. +//===----------------------------------------------------------------------===// + +namespace { +struct TargetLoongArch64 : public GenericTarget { + using GenericTarget::GenericTarget; + + static constexpr int defaultWidth = 64; + + CodeGenSpecifics::Marshalling + complexArgumentType(mlir::Location loc, mlir::Type eleTy) const override { + CodeGenSpecifics::Marshalling marshal; + const auto *sem = &floatToSemantics(kindMap, eleTy); + if (sem == &llvm::APFloat::IEEEsingle() || + sem == &llvm::APFloat::IEEEdouble()) { + // Two distinct element type arguments (re, im) + marshal.emplace_back(eleTy, AT{}); + marshal.emplace_back(eleTy, AT{}); + } else { + TODO(loc, "complex for this precision"); + } + return marshal; + } + + CodeGenSpecifics::Marshalling + complexReturnType(mlir::Location loc, mlir::Type eleTy) const override { + CodeGenSpecifics::Marshalling marshal; + const auto *sem = &floatToSemantics(kindMap, eleTy); + if (sem == &llvm::APFloat::IEEEsingle() || + sem == &llvm::APFloat::IEEEdouble()) { + // Use a type that will be translated into LLVM as: + // { t, t } struct of 2 eleTy, byVal + marshal.emplace_back(mlir::TupleType::get(eleTy.getContext(), + mlir::TypeRange{eleTy, eleTy}), + AT{/*alignment=*/0, /*byval=*/true}); + } else { + TODO(loc, "complex for this precision"); + } + return marshal; + } +}; +} // namespace + // Instantiate the overloaded target instance based on the triple value. // TODO: Add other targets to this file as needed. std::unique_ptr @@ -527,6 +571,9 @@ fir::CodeGenSpecifics::get(mlir::MLIRContext *ctx, llvm::Triple &&trp, case llvm::Triple::ArchType::amdgcn: return std::make_unique(ctx, std::move(trp), std::move(kindMap)); + case llvm::Triple::ArchType::loongarch64: + return std::make_unique(ctx, std::move(trp), + std::move(kindMap)); } TODO(mlir::UnknownLoc::get(ctx), "target not implemented"); } diff --git a/flang/test/Fir/target-rewrite-boxchar.fir b/flang/test/Fir/target-rewrite-boxchar.fir index 93c2059..e66fa60 100644 --- a/flang/test/Fir/target-rewrite-boxchar.fir +++ b/flang/test/Fir/target-rewrite-boxchar.fir @@ -3,6 +3,7 @@ // RUN: fir-opt --target-rewrite="target=aarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64 // RUN: fir-opt --target-rewrite="target=powerpc64le-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64 // RUN: fir-opt --target-rewrite="target=amdgcn-amd-amdhsa" %s | FileCheck %s --check-prefix=INT64 +// RUN: fir-opt --target-rewrite="target=loongarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64 // Test that we rewrite the signatures and bodies of functions that take boxchar // parameters. diff --git a/flang/test/Fir/target-rewrite-complex.fir b/flang/test/Fir/target-rewrite-complex.fir index 82d5923..bc28242 100644 --- a/flang/test/Fir/target-rewrite-complex.fir +++ b/flang/test/Fir/target-rewrite-complex.fir @@ -6,6 +6,7 @@ // RUN: fir-opt --target-rewrite="target=sparcv9-sun-solaris2.11" %s | FileCheck %s --check-prefix=SPARCV9 // RUN: fir-opt --target-rewrite="target=riscv64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=RISCV64 // RUN: fir-opt --target-rewrite="target=powerpc64-ibm-aix7.2.0.0" %s | FileCheck %s --check-prefix=PPC64 +// RUN: fir-opt --target-rewrite="target=loongarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=LOONGARCH64 // Test that we rewrite the signature and body of a function that returns a // complex<4>. @@ -16,6 +17,7 @@ // SPARCV9-LABEL: func @returncomplex4() -> tuple, !fir.real<4>> // RISCV64-LABEL: func @returncomplex4() -> tuple, !fir.real<4>> // PPC64-LABEL: func @returncomplex4() -> tuple, !fir.real<4>> +// LOONGARCH64-LABEL: func @returncomplex4() -> tuple, !fir.real<4>> func.func @returncomplex4() -> !fir.complex<4> { // I32: fir.insert_value // I32: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value @@ -31,6 +33,8 @@ func.func @returncomplex4() -> !fir.complex<4> { // RISCV64: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value // PPC64: fir.insert_value // PPC64: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value + // LOONGARCH64: fir.insert_value + // LOONGARCH64: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value %1 = fir.undefined !fir.complex<4> %2 = arith.constant 2.0 : f32 %3 = fir.convert %2 : (f32) -> !fir.real<4> @@ -72,6 +76,8 @@ func.func @returncomplex4() -> !fir.complex<4> { // PPC64: fir.store [[VAL]] to [[ADDRC]] : !fir.ref> // PPC64: [[RES:%[0-9A-Za-z]+]] = fir.load [[ADDRT]] : !fir.ref, !fir.real<4>>> // PPC64: return [[RES]] : tuple, !fir.real<4>> + // LOONGARCH64: [[ADDRT:%[0-9A-Za-z]+]] = fir.alloca tuple, !fir.real<4>> + // LOONGARCH64: [[ADDRC:%[0-9A-Za-z]+]] = fir.convert [[ADDRT]] : (!fir.ref, !fir.real<4>>>) -> !fir.ref> return %6 : !fir.complex<4> } @@ -85,6 +91,7 @@ func.func @returncomplex4() -> !fir.complex<4> { // SPARCV9-LABEL: func @returncomplex8() -> tuple, !fir.real<8>> // RISCV64-LABEL: func @returncomplex8() -> tuple, !fir.real<8>> // PPC64-LABEL: func @returncomplex8() -> tuple, !fir.real<8>> +// LOONGARCH64-LABEL: func @returncomplex8() -> tuple, !fir.real<8>> func.func @returncomplex8() -> !fir.complex<8> { // I32: fir.insert_value // I32: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value {{.*}} @@ -100,6 +107,8 @@ func.func @returncomplex8() -> !fir.complex<8> { // RISCV64: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value {{.*}} // PPC64: fir.insert_value // PPC64: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value {{.*}} + // LOONGARCH64: fir.insert_value + // LOONGARCH64: [[VAL:%[0-9A-Za-z]+]] = fir.insert_value {{.*}} %1 = fir.undefined !fir.complex<8> %2 = arith.constant 1.0 : f64 %3 = arith.constant -4.0 : f64 @@ -141,6 +150,11 @@ func.func @returncomplex8() -> !fir.complex<8> { // PPC64: fir.store [[VAL]] to [[ADDRC]] : !fir.ref> // PPC64: [[RES:%[0-9A-Za-z]+]] = fir.load [[ADDRT]] : !fir.ref, !fir.real<8>>> // PPC64: return [[RES]] : tuple, !fir.real<8>> + // LOONGARCH64: [[ADDRT:%[0-9A-Za-z]+]] = fir.alloca tuple, !fir.real<8>> + // LOONGARCH64: [[ADDRC:%[0-9A-Za-z]+]] = fir.convert [[ADDRT]] : (!fir.ref, !fir.real<8>>>) -> !fir.ref> + // LOONGARCH64: fir.store [[VAL]] to [[ADDRC]] : !fir.ref> + // LOONGARCH64: [[RES:%[0-9A-Za-z]+]] = fir.load [[ADDRT]] : !fir.ref, !fir.real<8>>> + // LOONGARCH64: return [[RES]] : tuple, !fir.real<8>> return %5 : !fir.complex<8> } @@ -152,6 +166,7 @@ func.func @returncomplex8() -> !fir.complex<8> { // SPARCV9-LABEL: func private @paramcomplex4(!fir.real<4>, !fir.real<4>) // RISCV64-LABEL: func private @paramcomplex4(!fir.real<4>, !fir.real<4>) // PPC64-LABEL: func private @paramcomplex4(!fir.real<4>, !fir.real<4>) +// LOONGARCH64-LABEL: func private @paramcomplex4(!fir.real<4>, !fir.real<4>) func.func private @paramcomplex4(!fir.complex<4>) -> () // Test that we rewrite calls to functions that return or accept complex<4>. @@ -162,6 +177,7 @@ func.func private @paramcomplex4(!fir.complex<4>) -> () // SPARCV9-LABEL: func @callcomplex4 // RISCV64-LABEL: func @callcomplex4 // PPC64-LABEL: func @callcomplex4 +// LOONGARCH64-LABEL: func @callcomplex4 func.func @callcomplex4(%arg0 : !fir.class>) { // I32: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex4() : () -> i64 @@ -171,6 +187,7 @@ func.func @callcomplex4(%arg0 : !fir.class tuple, !fir.real<4>> // RISCV64: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex4() : () -> tuple, !fir.real<4>> // PPC64: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex4() : () -> tuple, !fir.real<4>> + // LOONGARCH64: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex4() : () -> tuple, !fir.real<4>> %1 = fir.call @returncomplex4() : () -> !fir.complex<4> // I32: [[ADDRI64:%[0-9A-Za-z]+]] = fir.alloca i64 @@ -233,6 +250,14 @@ func.func @callcomplex4(%arg0 : !fir.class) -> !fir.real<4> // PPC64: [[B:%[0-9A-Za-z]+]] = fir.extract_value [[V]], [1 : i32] : (!fir.complex<4>) -> !fir.real<4> // PPC64: fir.call @paramcomplex4([[A]], [[B]]) : (!fir.real<4>, !fir.real<4>) -> () + + // LOONGARCH64: [[ADDRT:%[0-9A-Za-z]+]] = fir.alloca tuple, !fir.real<4>> + // LOONGARCH64: fir.store [[RES]] to [[ADDRT]] : !fir.ref, !fir.real<4>>> + // LOONGARCH64: [[ADDRC:%[0-9A-Za-z]+]] = fir.convert [[ADDRT]] : (!fir.ref, !fir.real<4>>>) -> !fir.ref> + // LOONGARCH64: [[V:%[0-9A-Za-z]+]] = fir.load [[ADDRC]] : !fir.ref> + // LOONGARCH64: [[A:%[0-9A-Za-z]+]] = fir.extract_value [[V]], [0 : i32] : (!fir.complex<4>) -> !fir.real<4> + // LOONGARCH64: [[B:%[0-9A-Za-z]+]] = fir.extract_value [[V]], [1 : i32] : (!fir.complex<4>) -> !fir.real<4> + // LOONGARCH64: fir.call @paramcomplex4([[A]], [[B]]) : (!fir.real<4>, !fir.real<4>) -> () fir.call @paramcomplex4(%1) : (!fir.complex<4>) -> () // I32: [[RES:%[0-9A-Za-z]+]] = fir.dispatch "ret_complex"(%{{.*}} : !fir.class>) (%{{.*}} : !fir.class>) -> i64 {pass_arg_pos = 0 : i32} @@ -305,6 +330,7 @@ func.func @callcomplex4(%arg0 : !fir.class>) (%{{.*}}, %{{.*}}, %{{.*}} : !fir.real<4>, !fir.real<4>, !fir.class>) {pass_arg_pos = 2 : i32} // RISCV64: fir.dispatch "with_complex2"(%{{.*}} : !fir.class>) (%{{.*}}, %{{.*}}, %{{.*}} : !fir.real<4>, !fir.real<4>, !fir.class>) {pass_arg_pos = 2 : i32} // PPC64: fir.dispatch "with_complex2"(%{{.*}} : !fir.class>) (%{{.*}}, %{{.*}}, %{{.*}} : !fir.real<4>, !fir.real<4>, !fir.class>) {pass_arg_pos = 2 : i32} + // LOONGARCH64: fir.dispatch "with_complex2"(%{{.*}} : !fir.class>) (%{{.*}}, %{{.*}}, %{{.*}} : !fir.real<4>, !fir.real<4>, !fir.class>) {pass_arg_pos = 2 : i32} fir.dispatch "with_complex2"(%arg0 : !fir.class>) (%2, %arg0 : !fir.complex<4>, !fir.class>) {pass_arg_pos = 1 : i32} return @@ -318,6 +344,7 @@ func.func @callcomplex4(%arg0 : !fir.class, !fir.real<8>) // RISCV64-LABEL: func private @paramcomplex8(!fir.real<8>, !fir.real<8>) // PPC64-LABEL: func private @paramcomplex8(!fir.real<8>, !fir.real<8>) +// LOONGARCH64-LABEL: func private @paramcomplex8(!fir.real<8>, !fir.real<8>) func.func private @paramcomplex8(!fir.complex<8>) -> () // Test that we rewrite calls to functions that return or accept complex<8>. @@ -328,6 +355,7 @@ func.func private @paramcomplex8(!fir.complex<8>) -> () // SPARCV9-LABEL: func @callcomplex8() // RISCV64-LABEL: func @callcomplex8() // PPC64-LABEL: func @callcomplex8() +// LOONGARCH64-LABEL: func @callcomplex8() func.func @callcomplex8() { // I32: [[RES:%[0-9A-Za-z]+]] = fir.alloca tuple, !fir.real<8>> // I32: fir.call @returncomplex8([[RES]]) : (!fir.ref, !fir.real<8>>>) -> () @@ -337,6 +365,7 @@ func.func @callcomplex8() { // SPARCV9: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex8() : () -> tuple, !fir.real<8>> // RISCV64: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex8() : () -> tuple, !fir.real<8>> // PPC64: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex8() : () -> tuple, !fir.real<8>> + // LOONGARCH64: [[RES:%[0-9A-Za-z]+]] = fir.call @returncomplex8() : () -> tuple, !fir.real<8>> %1 = fir.call @returncomplex8() : () -> !fir.complex<8> // I32: [[RESC:%[0-9A-Za-z]+]] = fir.convert [[RES]] : (!fir.ref, !fir.real<8>>>) -> !fir.ref> @@ -395,6 +424,14 @@ func.func @callcomplex8() { // PPC64: [[A:%[0-9A-Za-z]+]] = fir.extract_value [[V]], [0 : i32] : (!fir.complex<8>) -> !fir.real<8> // PPC64: [[B:%[0-9A-Za-z]+]] = fir.extract_value [[V]], [1 : i32] : (!fir.complex<8>) -> !fir.real<8> // PPC64: fir.call @paramcomplex8([[A]], [[B]]) : (!fir.real<8>, !fir.real<8>) -> () + + // LOONGARCH64: [[ADDRT:%[0-9A-Za-z]+]] = fir.alloca tuple, !fir.real<8>> + // LOONGARCH64: fir.store [[RES]] to [[ADDRT]] : !fir.ref, !fir.real<8>>> + // LOONGARCH64: [[ADDRC:%[0-9A-Za-z]+]] = fir.convert [[ADDRT]] : (!fir.ref, !fir.real<8>>>) -> !fir.ref> + // LOONGARCH64: [[V:%[0-9A-Za-z]+]] = fir.load [[ADDRC]] : !fir.ref> + // LOONGARCH64: [[A:%[0-9A-Za-z]+]] = fir.extract_value [[V]], [0 : i32] : (!fir.complex<8>) -> !fir.real<8> + // LOONGARCH64: [[B:%[0-9A-Za-z]+]] = fir.extract_value [[V]], [1 : i32] : (!fir.complex<8>) -> !fir.real<8> + // LOONGARCH64: fir.call @paramcomplex8([[A]], [[B]]) : (!fir.real<8>, !fir.real<8>) -> () fir.call @paramcomplex8(%1) : (!fir.complex<8>) -> () return @@ -408,6 +445,7 @@ func.func @callcomplex8() { // SPARCV9-LABEL: func private @calleemultipleparamscomplex4(!fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>) // RISCV64-LABEL: func private @calleemultipleparamscomplex4(!fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>) // PPC64-LABEL: func private @calleemultipleparamscomplex4(!fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>) +// LOONGARCH64-LABEL: func private @calleemultipleparamscomplex4(!fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>) func.func private @calleemultipleparamscomplex4(!fir.complex<4>, !fir.complex<4>, !fir.complex<4>) -> () // I32-LABEL: func @multipleparamscomplex4 @@ -424,6 +462,8 @@ func.func private @calleemultipleparamscomplex4(!fir.complex<4>, !fir.complex<4> // RISCV64-SAME: ([[A1:%[0-9A-Za-z]+]]: !fir.real<4>, [[B1:%[0-9A-Za-z]+]]: !fir.real<4>, [[A2:%[0-9A-Za-z]+]]: !fir.real<4>, [[B2:%[0-9A-Za-z]+]]: !fir.real<4>, [[A3:%[0-9A-Za-z]+]]: !fir.real<4>, [[B3:%[0-9A-Za-z]+]]: !fir.real<4>) // PPC64-LABEL: func @multipleparamscomplex4 // PPC64-SAME: ([[A1:%[0-9A-Za-z]+]]: !fir.real<4>, [[B1:%[0-9A-Za-z]+]]: !fir.real<4>, [[A2:%[0-9A-Za-z]+]]: !fir.real<4>, [[B2:%[0-9A-Za-z]+]]: !fir.real<4>, [[A3:%[0-9A-Za-z]+]]: !fir.real<4>, [[B3:%[0-9A-Za-z]+]]: !fir.real<4>) +// LOONGARCH64-LABEL: func @multipleparamscomplex4 +// LOONGARCH64-SAME: ([[A1:%[0-9A-Za-z]+]]: !fir.real<4>, [[B1:%[0-9A-Za-z]+]]: !fir.real<4>, [[A2:%[0-9A-Za-z]+]]: !fir.real<4>, [[B2:%[0-9A-Za-z]+]]: !fir.real<4>, [[A3:%[0-9A-Za-z]+]]: !fir.real<4>, [[B3:%[0-9A-Za-z]+]]: !fir.real<4>) func.func @multipleparamscomplex4(%z1 : !fir.complex<4>, %z2 : !fir.complex<4>, %z3 : !fir.complex<4>) { // I32-DAG: [[Z1_ADDR:%[0-9A-Za-z]+]] = fir.convert [[Z1]] : (!fir.ref, !fir.real<4>>>) -> !fir.ref> // I32-DAG: [[Z1_VAL:%[0-9A-Za-z]+]] = fir.load [[Z1_ADDR]] : !fir.ref> @@ -574,6 +614,24 @@ func.func @multipleparamscomplex4(%z1 : !fir.complex<4>, %z2 : !fir.complex<4>, // PPC64-DAG: [[B3_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z3]], [1 : i32] : (!fir.complex<4>) -> !fir.real<4> // PPC64: fir.call @calleemultipleparamscomplex4([[A1_EXTR]], [[B1_EXTR]], [[A2_EXTR]], [[B2_EXTR]], [[A3_EXTR]], [[B3_EXTR]]) : (!fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>) -> () + // LOONGARCH64-DAG: [[Z3_EMPTY:%[0-9A-Za-z]+]] = fir.undefined !fir.complex<4> + // LOONGARCH64-DAG: [[Z3_PARTIAL:%[0-9A-Za-z]+]] = fir.insert_value [[Z3_EMPTY]], [[A3]], [0 : i32] : (!fir.complex<4>, !fir.real<4>) -> !fir.complex<4> + // LOONGARCH64-DAG: [[Z3:%[0-9A-Za-z]+]] = fir.insert_value [[Z3_PARTIAL]], [[B3]], [1 : i32] : (!fir.complex<4>, !fir.real<4>) -> !fir.complex<4> + // LOONGARCH64-DAG: [[Z2_EMPTY:%[0-9A-Za-z]+]] = fir.undefined !fir.complex<4> + // LOONGARCH64-DAG: [[Z2_PARTIAL:%[0-9A-Za-z]+]] = fir.insert_value [[Z2_EMPTY]], [[A2]], [0 : i32] : (!fir.complex<4>, !fir.real<4>) -> !fir.complex<4> + // LOONGARCH64-DAG: [[Z2:%[0-9A-Za-z]+]] = fir.insert_value [[Z2_PARTIAL]], [[B2]], [1 : i32] : (!fir.complex<4>, !fir.real<4>) -> !fir.complex<4> + // LOONGARCH64-DAG: [[Z1_EMPTY:%[0-9A-Za-z]+]] = fir.undefined !fir.complex<4> + // LOONGARCH64-DAG: [[Z1_PARTIAL:%[0-9A-Za-z]+]] = fir.insert_value [[Z1_EMPTY]], [[A1]], [0 : i32] : (!fir.complex<4>, !fir.real<4>) -> !fir.complex<4> + // LOONGARCH64-DAG: [[Z1:%[0-9A-Za-z]+]] = fir.insert_value [[Z1_PARTIAL]], [[B1]], [1 : i32] : (!fir.complex<4>, !fir.real<4>) -> !fir.complex<4> + + // LOONGARCH64-DAG: [[A1_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z1]], [0 : i32] : (!fir.complex<4>) -> !fir.real<4> + // LOONGARCH64-DAG: [[B1_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z1]], [1 : i32] : (!fir.complex<4>) -> !fir.real<4> + // LOONGARCH64-DAG: [[A2_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z2]], [0 : i32] : (!fir.complex<4>) -> !fir.real<4> + // LOONGARCH64-DAG: [[B2_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z2]], [1 : i32] : (!fir.complex<4>) -> !fir.real<4> + // LOONGARCH64-DAG: [[A3_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z3]], [0 : i32] : (!fir.complex<4>) -> !fir.real<4> + // LOONGARCH64-DAG: [[B3_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z3]], [1 : i32] : (!fir.complex<4>) -> !fir.real<4> + + // LOONGARCH64: fir.call @calleemultipleparamscomplex4([[A1_EXTR]], [[B1_EXTR]], [[A2_EXTR]], [[B2_EXTR]], [[A3_EXTR]], [[B3_EXTR]]) : (!fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>, !fir.real<4>) -> () fir.call @calleemultipleparamscomplex4(%z1, %z2, %z3) : (!fir.complex<4>, !fir.complex<4>, !fir.complex<4>) -> () return } @@ -602,6 +660,9 @@ func.func @multipleparamscomplex4(%z1 : !fir.complex<4>, %z2 : !fir.complex<4>, // PPC64-LABEL: func private @mlircomplexf32 // PPC64-SAME: ([[A1:%[0-9A-Za-z]+]]: f32, [[B1:%[0-9A-Za-z]+]]: f32, [[A2:%[0-9A-Za-z]+]]: f32, [[B2:%[0-9A-Za-z]+]]: f32) // PPC64-SAME: -> tuple +// LOONGARCH64-LABEL: func private @mlircomplexf32 +// LOONGARCH64-SAME: ([[A1:%[0-9A-Za-z]+]]: f32, [[B1:%[0-9A-Za-z]+]]: f32, [[A2:%[0-9A-Za-z]+]]: f32, [[B2:%[0-9A-Za-z]+]]: f32) +// LOONGARCH64-SAME: -> tuple func.func private @mlircomplexf32(%z1: complex, %z2: complex) -> complex { // I32-DAG: [[Z1_ADDR:%[0-9A-Za-z]+]] = fir.convert [[Z1]] : (!fir.ref>) -> !fir.ref> @@ -713,6 +774,20 @@ func.func private @mlircomplexf32(%z1: complex, %z2: complex) -> compl // PPC64-DAG: [[B2_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z2]], [1 : i32] : (complex) -> f32 // PPC64: [[VAL:%[0-9A-Za-z]+]] = fir.call @mlircomplexf32([[A1_EXTR]], [[B1_EXTR]], [[A2_EXTR]], [[B2_EXTR]]) : (f32, f32, f32, f32) -> tuple + + // LOONGARCH64-DAG: [[Z2_EMPTY:%[0-9A-Za-z]+]] = fir.undefined complex + // LOONGARCH64-DAG: [[Z2_PARTIAL:%[0-9A-Za-z]+]] = fir.insert_value [[Z2_EMPTY]], [[A2]], [0 : i32] : (complex, f32) -> complex + // LOONGARCH64-DAG: [[Z2:%[0-9A-Za-z]+]] = fir.insert_value [[Z2_PARTIAL]], [[B2]], [1 : i32] : (complex, f32) -> complex + // LOONGARCH64-DAG: [[Z1_EMPTY:%[0-9A-Za-z]+]] = fir.undefined complex + // LOONGARCH64-DAG: [[Z1_PARTIAL:%[0-9A-Za-z]+]] = fir.insert_value [[Z1_EMPTY]], [[A1]], [0 : i32] : (complex, f32) -> complex + // LOONGARCH64-DAG: [[Z1:%[0-9A-Za-z]+]] = fir.insert_value [[Z1_PARTIAL]], [[B1]], [1 : i32] : (complex, f32) -> complex + + // LOONGARCH64-DAG: [[A1_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z1]], [0 : i32] : (complex) -> f32 + // LOONGARCH64-DAG: [[B1_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z1]], [1 : i32] : (complex) -> f32 + // LOONGARCH64-DAG: [[A2_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z2]], [0 : i32] : (complex) -> f32 + // LOONGARCH64-DAG: [[B2_EXTR:%[0-9A-Za-z]+]] = fir.extract_value [[Z2]], [1 : i32] : (complex) -> f32 + + // LOONGARCH64: [[VAL:%[0-9A-Za-z]+]] = fir.call @mlircomplexf32([[A1_EXTR]], [[B1_EXTR]], [[A2_EXTR]], [[B2_EXTR]]) : (f32, f32, f32, f32) -> tuple %0 = fir.call @mlircomplexf32(%z1, %z2) : (complex, complex) -> complex // I32: [[ADDRI64:%[0-9A-Za-z]+]] = fir.alloca i64 @@ -784,6 +859,16 @@ func.func private @mlircomplexf32(%z1: complex, %z2: complex) -> compl // PPC64: fir.store [[V]] to [[ADDRC_2]] : !fir.ref> // PPC64: [[RES:%[0-9A-Za-z]+]] = fir.load [[ADDRT_2]] : !fir.ref> // PPC64: return [[RES]] : tuple + + // LOONGARCH64: [[ADDRT:%[0-9A-Za-z]+]] = fir.alloca tuple + // LOONGARCH64: fir.store [[VAL]] to [[ADDRT]] : !fir.ref> + // LOONGARCH64: [[ADDRC:%[0-9A-Za-z]+]] = fir.convert [[ADDRT]] : (!fir.ref>) -> !fir.ref> + // LOONGARCH64: [[V:%[0-9A-Za-z]+]] = fir.load [[ADDRC]] : !fir.ref> + // LOONGARCH64: [[ADDRT_2:%[0-9A-Za-z]+]] = fir.alloca tuple + // LOONGARCH64: [[ADDRC_2:%[0-9A-Za-z]+]] = fir.convert [[ADDRT_2]] : (!fir.ref>) -> !fir.ref> + // LOONGARCH64: fir.store [[V]] to [[ADDRC_2]] : !fir.ref> + // LOONGARCH64: [[RES:%[0-9A-Za-z]+]] = fir.load [[ADDRT_2]] : !fir.ref> + // LOONGARCH64: return [[RES]] : tuple return %0 : complex } @@ -795,6 +880,7 @@ func.func private @mlircomplexf32(%z1: complex, %z2: complex) -> compl // SPARCV9-LABEL: func @addrof() // RISCV64-LABEL: func @addrof() // PPC64-LABEL: func @addrof() +// LOONGARCH64-LABEL: func @addrof() func.func @addrof() { // I32: {{%.*}} = fir.address_of(@returncomplex4) : () -> i64 // X64: {{%.*}} = fir.address_of(@returncomplex4) : () -> !fir.vector<2:!fir.real<4>> @@ -802,6 +888,7 @@ func.func @addrof() { // PPC64le: {{%.*}} = fir.address_of(@returncomplex4) : () -> tuple, !fir.real<4>> // RISCV64: {{%.*}} = fir.address_of(@returncomplex4) : () -> tuple, !fir.real<4>> // PPC64: {{%.*}} = fir.address_of(@returncomplex4) : () -> tuple, !fir.real<4>> + // LOONGARCH64: {{%.*}} = fir.address_of(@returncomplex4) : () -> tuple, !fir.real<4>> %r = fir.address_of(@returncomplex4) : () -> !fir.complex<4> // I32: {{%.*}} = fir.address_of(@paramcomplex4) : (!fir.ref, !fir.real<4>>>) -> () @@ -811,6 +898,7 @@ func.func @addrof() { // SPARCV9: {{%.*}} = fir.address_of(@paramcomplex4) : (!fir.real<4>, !fir.real<4>) -> () // RISCV64: {{%.*}} = fir.address_of(@paramcomplex4) : (!fir.real<4>, !fir.real<4>) -> () // PPC64: {{%.*}} = fir.address_of(@paramcomplex4) : (!fir.real<4>, !fir.real<4>) -> () + // LOONGARCH64: {{%.*}} = fir.address_of(@paramcomplex4) : (!fir.real<4>, !fir.real<4>) -> () %p = fir.address_of(@paramcomplex4) : (!fir.complex<4>) -> () return } diff --git a/flang/test/Fir/target-rewrite-integer.fir b/flang/test/Fir/target-rewrite-integer.fir index b7426ac..7bc4e4a 100644 --- a/flang/test/Fir/target-rewrite-integer.fir +++ b/flang/test/Fir/target-rewrite-integer.fir @@ -4,6 +4,7 @@ // RUN: fir-opt --split-input-file --target-rewrite="target=powerpc64le-unknown-linux-gnu" %s | FileCheck %s --check-prefixes=PPC,ALL // RUN: fir-opt --split-input-file --target-rewrite="target=sparc64-unknown-linux-gnu" %s | FileCheck %s --check-prefixes=SPARCV9,ALL // RUN: fir-opt --split-input-file --target-rewrite="target=sparcv9-sun-solaris2.11" %s | FileCheck %s --check-prefixes=SPARCV9,ALL +// RUN: fir-opt --split-input-file --target-rewrite="target=loongarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefixes=LOONGARCH64,ALL // ----- @@ -18,6 +19,7 @@ // AARCH64: func.func{{.*}}@_FortranAioOutputLogical({{.*}}i1 {llvm.zeroext}) -> (i1 {llvm.zeroext}) // PPC: func.func{{.*}}@_FortranAioOutputLogical({{.*}}i1 {llvm.zeroext}) -> (i1 {llvm.zeroext}) // SPARCV9: func.func{{.*}}@_FortranAioOutputLogical({{.*}}i1 {llvm.zeroext}) -> (i1 {llvm.zeroext}) +// LOONGARCH64: func.func{{.*}}@_FortranAioOutputLogical({{.*}}i1 {llvm.zeroext}) -> (i1 {llvm.zeroext}) func.func @_QPtest_i1(%arg0: !fir.ref> {fir.bindc_name = "x"}) { %c3_i32 = arith.constant 3 : i32 %c-1_i32 = arith.constant -1 : i32 @@ -49,6 +51,7 @@ func.func private @_FortranAioEndIoStatement(!fir.ref) -> i32 attributes {fi // AARCH64: func.func{{.*}}@_SomeFunc_si1(si1 {llvm.signext}) -> (si1 {llvm.signext}) // PPC: func.func{{.*}}@_SomeFunc_si1(si1 {llvm.signext}) -> (si1 {llvm.signext}) // SPARCV9: func.func{{.*}}@_SomeFunc_si1(si1 {llvm.signext}) -> (si1 {llvm.signext}) +// LOONGARCH64: func.func{{.*}}@_SomeFunc_si1(si1 {llvm.signext}) -> (si1 {llvm.signext}) func.func @_QPtest_si1(%arg0: !fir.ref> {fir.bindc_name = "x"}) { %0 = fir.load %arg0 : !fir.ref> %1 = fir.convert %0 : (!fir.logical<4>) -> si1 @@ -68,6 +71,7 @@ func.func private @_SomeFunc_si1(si1) -> si1 attributes {fir.runtime} // AARCH64: func.func{{.*}}@_SomeFunc_ui1(ui1 {llvm.zeroext}) -> (ui1 {llvm.zeroext}) // PPC: func.func{{.*}}@_SomeFunc_ui1(ui1 {llvm.zeroext}) -> (ui1 {llvm.zeroext}) // SPARCV9: func.func{{.*}}@_SomeFunc_ui1(ui1 {llvm.zeroext}) -> (ui1 {llvm.zeroext}) +// LOONGARCH64: func.func{{.*}}@_SomeFunc_ui1(ui1 {llvm.zeroext}) -> (ui1 {llvm.zeroext}) func.func @_QPtest_ui1(%arg0: !fir.ref> {fir.bindc_name = "x"}) { %0 = fir.load %arg0 : !fir.ref> %1 = fir.convert %0 : (!fir.logical<4>) -> ui1