xref: /freebsd/contrib/llvm-project/openmp/runtime/src/ompt-internal.h (revision 9e5787d2284e187abb5b654d924394a65772e004)
1 /*
2  * ompt-internal.h - header of OMPT internal data structures
3  */
4 
5 //===----------------------------------------------------------------------===//
6 //
7 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
8 // See https://llvm.org/LICENSE.txt for license information.
9 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef __OMPT_INTERNAL_H__
14 #define __OMPT_INTERNAL_H__
15 
16 #include "ompt-event-specific.h"
17 #include "omp-tools.h"
18 
19 #define OMPT_VERSION 1
20 
21 #define _OMP_EXTERN extern "C"
22 
23 #define OMPT_INVOKER(x)                                                        \
24   ((x == fork_context_gnu) ? ompt_parallel_invoker_program                     \
25                            : ompt_parallel_invoker_runtime)
26 
27 #define ompt_callback(e) e##_callback
28 
29 typedef struct ompt_callbacks_internal_s {
30 #define ompt_event_macro(event, callback, eventid)                             \
31   callback ompt_callback(event);
32 
33   FOREACH_OMPT_EVENT(ompt_event_macro)
34 
35 #undef ompt_event_macro
36 } ompt_callbacks_internal_t;
37 
38 typedef struct ompt_callbacks_active_s {
39   unsigned int enabled : 1;
40 #define ompt_event_macro(event, callback, eventid) unsigned int event : 1;
41 
42   FOREACH_OMPT_EVENT(ompt_event_macro)
43 
44 #undef ompt_event_macro
45 } ompt_callbacks_active_t;
46 
47 #define TASK_TYPE_DETAILS_FORMAT(info)                                         \
48   ((info->td_flags.task_serial || info->td_flags.tasking_ser)                  \
49        ? ompt_task_undeferred                                                  \
50        : 0x0) |                                                                \
51       ((!(info->td_flags.tiedness)) ? ompt_task_untied : 0x0) |                \
52       (info->td_flags.final ? ompt_task_final : 0x0) |                         \
53       (info->td_flags.merged_if0 ? ompt_task_mergeable : 0x0)
54 
55 typedef struct {
56   ompt_frame_t frame;
57   ompt_data_t task_data;
58   struct kmp_taskdata *scheduling_parent;
59   int thread_num;
60 } ompt_task_info_t;
61 
62 typedef struct {
63   ompt_data_t parallel_data;
64   void *master_return_address;
65 } ompt_team_info_t;
66 
67 typedef struct ompt_lw_taskteam_s {
68   ompt_team_info_t ompt_team_info;
69   ompt_task_info_t ompt_task_info;
70   int heap;
71   struct ompt_lw_taskteam_s *parent;
72 } ompt_lw_taskteam_t;
73 
74 typedef struct {
75   ompt_data_t thread_data;
76   ompt_data_t task_data; /* stored here from implicit barrier-begin until
77                             implicit-task-end */
78   void *return_address; /* stored here on entry of runtime */
79   ompt_state_t state;
80   ompt_wait_id_t wait_id;
81   int ompt_task_yielded;
82   int parallel_flags; // information for the last parallel region invoked
83   void *idle_frame;
84 } ompt_thread_info_t;
85 
86 extern ompt_callbacks_internal_t ompt_callbacks;
87 
88 #if OMPT_SUPPORT && OMPT_OPTIONAL
89 #if USE_FAST_MEMORY
90 #define KMP_OMPT_DEPS_ALLOC __kmp_fast_allocate
91 #define KMP_OMPT_DEPS_FREE __kmp_fast_free
92 #else
93 #define KMP_OMPT_DEPS_ALLOC __kmp_thread_malloc
94 #define KMP_OMPT_DEPS_FREE __kmp_thread_free
95 #endif
96 #endif /* OMPT_SUPPORT && OMPT_OPTIONAL */
97 
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101 
102 void ompt_pre_init(void);
103 void ompt_post_init(void);
104 void ompt_fini(void);
105 
106 #define OMPT_GET_RETURN_ADDRESS(level) __builtin_return_address(level)
107 #define OMPT_GET_FRAME_ADDRESS(level) __builtin_frame_address(level)
108 
109 int __kmp_control_tool(uint64_t command, uint64_t modifier, void *arg);
110 
111 extern ompt_callbacks_active_t ompt_enabled;
112 
113 #if KMP_OS_WINDOWS
114 #define UNLIKELY(x) (x)
115 #define OMPT_NOINLINE __declspec(noinline)
116 #else
117 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
118 #define OMPT_NOINLINE __attribute__((noinline))
119 #endif
120 
121 #ifdef __cplusplus
122 };
123 #endif
124 
125 #endif
126