[llvm-branch-commits] [flang] [flang][acc] Emit acc.on_device operation for acc_on_device call (PR #208098)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jul 8 06:42:32 PDT 2026
================
@@ -0,0 +1,51 @@
+//===-- OpenACCIntrinsicCall.cpp ------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Optimizer/Builder/OpenACCIntrinsicCall.h"
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "mlir/Dialect/OpenACC/OpenACC.h"
+
+namespace fir {
+
+using OAI = OpenACCIntrinsicLibrary;
+
+static constexpr IntrinsicHandler openaccHandlers[]{
+ {"acc_on_device",
+ static_cast<OpenACCIntrinsicLibrary::ElementalGenerator>(
+ &OAI::genACCOnDevice),
+ {{{"devtype", asValue}}},
+ /*isElemental=*/false},
+};
+static_assert(fir::isSorted(openaccHandlers) && "map must be sorted");
+
+const IntrinsicHandler *findOpenACCIntrinsicHandler(llvm::StringRef name,
+ bool isBindcCall) {
+ if (!isBindcCall)
+ return nullptr;
+ auto compare = [](const IntrinsicHandler &openaccHandler,
+ llvm::StringRef name) {
+ return name.compare(openaccHandler.name) > 0;
+ };
+ auto result = llvm::lower_bound(openaccHandlers, name, compare);
+ return result != std::end(openaccHandlers) && result->name == name ? result
+ : nullptr;
+}
+
+mlir::Value
+OpenACCIntrinsicLibrary::genACCOnDevice(mlir::Type resultType,
+ llvm::ArrayRef<mlir::Value> args) {
+ assert(args.size() == 1);
+ mlir::Value deviceType = args[0];
+ if (deviceType.getType() != builder.getI32Type())
+ deviceType = builder.createConvert(loc, builder.getI32Type(), deviceType);
----------------
jeanPerier wrote:
nit: builder.createConvert is doing the `if (deviceType.getType() != builder.getI32Type())` already.
https://github.com/llvm/llvm-project/pull/208098
More information about the llvm-branch-commits
mailing list