Skip to content

[OpenMP] Add TargetAMDGPU support for Complex argument and return types #144924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions flang/lib/Optimizer/CodeGen/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refactoring the common logic used to compute float semantics in both complexArgumentType and complexReturnType to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.

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;
}
};
Expand Down
Loading