[memprof] Use a new constructor of IndexedAllocationInfo (NFC) (#116920)
[llvm-project.git] / openmp / libompd / src / omp-state.cpp
blobca87907aa6b2c7bba415855975a25da90a64cf77
1 /*
2 * omp-state.cpp -- OMPD states
3 */
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
11 //===----------------------------------------------------------------------===//
13 #include "omp-debug.h"
14 #include "ompd-private.h"
15 #include <cstring>
17 void __ompd_init_states(const ompd_callbacks_t *table) { callbacks = table; }
19 static const char *get_ompd_state_name(ompd_word_t state) {
20 switch (state) {
21 #define ompd_state_macro(state, code) \
22 case code: \
23 return #state;
24 FOREACH_OMPD_STATE(ompd_state_macro)
25 #undef ompd_state_macro
26 default:
27 return NULL;
31 ompd_rc_t
32 ompd_enumerate_states(ompd_address_space_handle_t *address_space_handle,
33 ompd_word_t current_state, ompd_word_t *next_state,
34 const char **next_state_name, ompd_word_t *more_enums) {
35 ompd_rc_t ret;
36 if (current_state > ompt_state_undefined &&
37 current_state >= OMPD_LAST_OMP_STATE) {
38 return ompd_rc_bad_input;
40 const char *find_next_state_name;
41 *next_state = (current_state == ompt_state_undefined ? ompt_state_work_serial
42 : current_state + 1);
43 while (!(find_next_state_name = get_ompd_state_name(*next_state))) {
44 ++(*next_state);
47 char *next_state_name_cpy;
48 ret = callbacks->alloc_memory(strlen(find_next_state_name) + 1,
49 (void **)&next_state_name_cpy);
50 if (ret != ompd_rc_ok) {
51 return ret;
53 strcpy(next_state_name_cpy, find_next_state_name);
55 *next_state_name = next_state_name_cpy;
57 if (*next_state == OMPD_LAST_OMP_STATE) {
58 *more_enums = 0;
59 } else {
60 *more_enums = 1;
63 return ompd_rc_ok;