[NFC][opt] Improve help message (#97805)
[llvm-project.git] / offload / include / OffloadPolicy.h
blob858d9c323b15a20caf638551e72a0e00218ca449
1 //===-- OffloadPolicy.h - Configuration of offload behavior -----*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Configuration for offload behavior, e.g., if offload is disabled, can be
10 // disabled, is mandatory, etc.
12 //===----------------------------------------------------------------------===//
14 #ifndef OMPTARGET_OFFLOAD_POLICY_H
15 #define OMPTARGET_OFFLOAD_POLICY_H
17 #include "PluginManager.h"
19 enum kmp_target_offload_kind_t {
20 tgt_disabled = 0,
21 tgt_default = 1,
22 tgt_mandatory = 2
25 extern "C" int __kmpc_get_target_offload(void) __attribute__((weak));
27 class OffloadPolicy {
29 OffloadPolicy(PluginManager &PM) {
30 // TODO: Check for OpenMP.
31 switch ((kmp_target_offload_kind_t)__kmpc_get_target_offload()) {
32 case tgt_disabled:
33 Kind = DISABLED;
34 return;
35 case tgt_mandatory:
36 Kind = MANDATORY;
37 return;
38 default:
39 if (PM.getNumDevices()) {
40 DP("Default TARGET OFFLOAD policy is now mandatory "
41 "(devices were found)\n");
42 Kind = MANDATORY;
43 } else {
44 DP("Default TARGET OFFLOAD policy is now disabled "
45 "(no devices were found)\n");
46 Kind = DISABLED;
48 return;
52 public:
53 static const OffloadPolicy &get(PluginManager &PM) {
54 static OffloadPolicy OP(PM);
55 return OP;
58 enum OffloadPolicyKind { DISABLED, MANDATORY };
60 OffloadPolicyKind Kind = MANDATORY;
63 #endif // OMPTARGET_OFFLOAD_POLICY_H