Skip to content

Commit 20b442a

Browse files
authored
[Flang][LoongArch] Add support for complex16 params/returns. (#114732)
In LoongArch64, the passing and returning of type `complex16` is similar to that of structure type like `struct {fp128, fp128}`, meaning they are passed and returned by reference. This behavior is similar to clang, so it can implement conveniently `iso_c_binding`. Additionally, this patch fixes the failure in flang test Integration/debug-complex-1.f90: ``` llvm-project/flang/lib/Optimizer/codeGen/Target.cpp:56: not yet implemented: complex for this precision for return type
1 parent d56f517 commit 20b442a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

flang/lib/Optimizer/CodeGen/Target.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,13 @@ struct TargetLoongArch64 : public GenericTarget<TargetLoongArch64> {
10911091
// Two distinct element type arguments (re, im)
10921092
marshal.emplace_back(eleTy, AT{});
10931093
marshal.emplace_back(eleTy, AT{});
1094+
} else if (sem == &llvm::APFloat::IEEEquad()) {
1095+
// Use a type that will be translated into LLVM as:
1096+
// { fp128, fp128 } struct of 2 fp128, byval
1097+
marshal.emplace_back(
1098+
fir::ReferenceType::get(mlir::TupleType::get(
1099+
eleTy.getContext(), mlir::TypeRange{eleTy, eleTy})),
1100+
AT{/*align=*/16, /*byval=*/true});
10941101
} else {
10951102
typeTodo(sem, loc, "argument");
10961103
}
@@ -1108,6 +1115,13 @@ struct TargetLoongArch64 : public GenericTarget<TargetLoongArch64> {
11081115
marshal.emplace_back(mlir::TupleType::get(eleTy.getContext(),
11091116
mlir::TypeRange{eleTy, eleTy}),
11101117
AT{/*alignment=*/0, /*byval=*/true});
1118+
} else if (sem == &llvm::APFloat::IEEEquad()) {
1119+
// Use a type that will be translated into LLVM as:
1120+
// { fp128, fp128 } struct of 2 fp128, sret, align 16
1121+
marshal.emplace_back(
1122+
fir::ReferenceType::get(mlir::TupleType::get(
1123+
eleTy.getContext(), mlir::TypeRange{eleTy, eleTy})),
1124+
AT{/*align=*/16, /*byval=*/false, /*sret=*/true});
11111125
} else {
11121126
typeTodo(sem, loc, "return");
11131127
}

flang/test/Fir/target-rewrite-complex16.fir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: fir-opt --target-rewrite="target=x86_64-unknown-linux-gnu" %s | FileCheck %s
2+
// RUN: fir-opt --target-rewrite="target=loongarch64-unknown-linux-gnu" %s | FileCheck %s
23

34
// Test that we rewrite the signature and body of a func.function that returns a
45
// complex<16>.

0 commit comments

Comments
 (0)