[OpenMP] Add TargetAMDGPU support for Complex argument and return types#144924
Merged
[OpenMP] Add TargetAMDGPU support for Complex argument and return types#144924
Conversation
This patch adds TargetAMDGPU offloading support for Complex argument and return types.
Member
|
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-flang-codegen Author: Akash Banerjee (TIFitis) ChangesThis patch adds TargetAMDGPU offloading support for Complex argument and return types. Full diff: https://github.com/llvm/llvm-project/pull/144924.diff 1 Files Affected:
diff --git a/flang/lib/Optimizer/CodeGen/Target.cpp b/flang/lib/Optimizer/CodeGen/Target.cpp
index 7dbf21ce0c125..b60a72e4340b9 100644
--- a/flang/lib/Optimizer/CodeGen/Target.cpp
+++ b/flang/lib/Optimizer/CodeGen/Target.cpp
@@ -1443,14 +1443,35 @@ struct TargetAMDGPU : public GenericTarget<TargetAMDGPU> {
CodeGenSpecifics::Marshalling
complexArgumentType(mlir::Location loc, mlir::Type eleTy) const override {
CodeGenSpecifics::Marshalling marshal;
- TODO(loc, "handle complex argument types");
+ const auto *sem = &floatToSemantics(kindMap, eleTy);
+ if (sem == &llvm::APFloat::IEEEsingle()) {
+ // Lower COMPLEX(KIND=4) as an array of two element values.
+ marshal.emplace_back(fir::SequenceType::get({2}, eleTy), AT{});
+ } else if (sem == &llvm::APFloat::IEEEdouble()) {
+ // Pass COMPLEX(KIND=8) as two separate arguments.
+ marshal.emplace_back(eleTy, AT{});
+ marshal.emplace_back(eleTy, AT{});
+ } else {
+ typeTodo(sem, loc, "argument");
+ }
return marshal;
}
CodeGenSpecifics::Marshalling
complexReturnType(mlir::Location loc, mlir::Type eleTy) const override {
CodeGenSpecifics::Marshalling marshal;
- TODO(loc, "handle complex return types");
+ const auto *sem = &floatToSemantics(kindMap, eleTy);
+ if (sem == &llvm::APFloat::IEEEsingle()) {
+ // Return COMPLEX(KIND=4) as an array of two elements.
+ marshal.emplace_back(fir::SequenceType::get({2}, eleTy), AT{});
+ } else if (sem == &llvm::APFloat::IEEEdouble()) {
+ // Return COMPLEX(KIND=8) via an aggregate with two fields.
+ marshal.emplace_back(mlir::TupleType::get(eleTy.getContext(),
+ mlir::TypeRange{eleTy, eleTy}),
+ AT{});
+ } else {
+ typeTodo(sem, loc, "return");
+ }
return marshal;
}
};
|
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces offloading support for complex argument and return types for TargetAMDGPU. The key changes include:
- Adding marshalling logic in complexArgumentType to handle COMPLEX(KIND=4) and COMPLEX(KIND=8).
- Implementing similar logic in complexReturnType with requirements differing in return type aggregation.
| complexArgumentType(mlir::Location loc, mlir::Type eleTy) const override { | ||
| CodeGenSpecifics::Marshalling marshal; | ||
| TODO(loc, "handle complex argument types"); | ||
| const auto *sem = &floatToSemantics(kindMap, eleTy); |
There was a problem hiding this comment.
[nitpick] Consider refactoring the common logic used to compute float semantics in both complexArgumentType and complexReturnType to reduce duplication and improve maintainability.
This was referenced Jun 19, 2025
Member
Author
|
Polite reminder for review, thanks. |
This was referenced Jul 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch adds TargetAMDGPU offloading support for Complex argument and return types.