10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
13
- #ifndef OMPT_SUPPORT
14
-
15
- extern " C" {
16
- // / Dummy definition when OMPT is disabled
17
- void ompt_libomptarget_connect () {}
18
- }
19
-
20
- #else // OMPT_SUPPORT is set
13
+ #ifdef OMPT_SUPPORT
21
14
22
15
#include < atomic>
23
16
#include < cassert>
@@ -27,27 +20,28 @@ void ompt_libomptarget_connect() {}
27
20
#include < mutex>
28
21
#include < thread>
29
22
30
- #pragma push_macro("DEBUG_PREFIX")
31
23
#include " Shared/Debug.h"
32
24
33
25
#include " OpenMP/OMPT/Callback.h"
34
26
#include " OpenMP/OMPT/Connector.h"
35
27
#include " OpenMP/OMPT/Interface.h"
36
28
37
29
#include " llvm/Support/DynamicLibrary.h"
30
+ #include " llvm/Support/ErrorHandling.h"
38
31
32
+ #pragma push_macro("DEBUG_PREFIX")
39
33
#undef DEBUG_PREFIX
40
34
#define DEBUG_PREFIX " OMPT"
41
35
42
- using namespace llvm ::omp::target::ompt;
43
-
44
36
// Define OMPT callback functions (bound to actual callbacks later on)
45
37
#define defineOmptCallback (Name, Type, Code ) \
46
38
Name##_t llvm::omp::target::ompt::Name##_fn = nullptr ;
47
39
FOREACH_OMPT_NOEMI_EVENT (defineOmptCallback)
48
40
FOREACH_OMPT_EMI_EVENT(defineOmptCallback)
49
41
#undef defineOmptCallback
50
42
43
+ using namespace llvm ::omp::target::ompt;
44
+
51
45
// / Forward declaration
52
46
class LibomptargetRtlFinalizer ;
53
47
@@ -58,15 +52,13 @@ thread_local Interface llvm::omp::target::ompt::RegionInterface;
58
52
59
53
thread_local void *llvm::omp::target::ompt::ReturnAddress = nullptr ;
60
54
61
- bool llvm::omp::target::ompt::CallbacksInitialized = false ;
55
+ bool llvm::omp::target::ompt::Initialized = false ;
62
56
63
57
ompt_get_callback_t llvm::omp::target::ompt::lookupCallbackByCode = nullptr ;
64
58
ompt_function_lookup_t llvm::omp::target::ompt::lookupCallbackByName = nullptr ;
65
- ompt_get_target_task_data_t
66
- llvm::omp::target::ompt::ompt_get_target_task_data_fn = nullptr ;
67
- ompt_get_task_data_t llvm::omp::target::ompt::ompt_get_task_data_fn = nullptr ;
68
- ompt_set_frame_enter_t llvm::omp::target::ompt::ompt_set_frame_enter_fn =
69
- nullptr ;
59
+ ompt_get_target_task_data_t ompt_get_target_task_data_fn = nullptr ;
60
+ ompt_get_task_data_t ompt_get_task_data_fn = nullptr ;
61
+ ompt_set_frame_enter_t ompt_set_frame_enter_fn = nullptr ;
70
62
71
63
// / Unique correlation id
72
64
static std::atomic<uint64_t > IdCounter (1 );
@@ -482,10 +474,11 @@ class LibomptargetRtlFinalizer {
482
474
int llvm::omp::target::ompt::initializeLibrary (ompt_function_lookup_t lookup,
483
475
int initial_device_num,
484
476
ompt_data_t *tool_data) {
485
- DP (" Executing initializeLibrary (libomp) \n " );
477
+ DP (" Executing initializeLibrary\n " );
486
478
#define bindOmptFunctionName (OmptFunction, DestinationFunction ) \
487
- DestinationFunction = (OmptFunction##_t)lookup (#OmptFunction); \
488
- DP (" initializeLibrary (libomp) bound %s=%p\n " , #DestinationFunction, \
479
+ if (lookup) \
480
+ DestinationFunction = (OmptFunction##_t)lookup (#OmptFunction); \
481
+ DP (" initializeLibrary bound %s=%p\n " , #DestinationFunction, \
489
482
((void *)(uint64_t )DestinationFunction));
490
483
491
484
bindOmptFunctionName (ompt_get_callback, lookupCallbackByCode);
@@ -509,22 +502,22 @@ int llvm::omp::target::ompt::initializeLibrary(ompt_function_lookup_t lookup,
509
502
510
503
LibraryFinalizer = new LibomptargetRtlFinalizer ();
511
504
512
- CallbacksInitialized = true ;
505
+ Initialized = true ;
513
506
514
507
return 0 ;
515
508
}
516
509
517
510
void llvm::omp::target::ompt::finalizeLibrary (ompt_data_t *data) {
518
- DP (" Executing finalizeLibrary (libomp) \n " );
511
+ DP (" Executing finalizeLibrary\n " );
519
512
// Before disabling OMPT, call the (plugin) finalizations that were registered
520
513
// with this library
521
514
LibraryFinalizer->finalize ();
522
515
delete LibraryFinalizer;
523
- CallbacksInitialized = false ;
516
+ Initialized = false ;
524
517
}
525
518
526
519
void llvm::omp::target::ompt::connectLibrary () {
527
- DP (" Entering connectLibrary (libomp) \n " );
520
+ DP (" Entering connectLibrary\n " );
528
521
// Connect with libomp
529
522
static OmptLibraryConnectorTy LibompConnector (" libomp" );
530
523
static ompt_start_tool_result_t OmptResult;
@@ -547,24 +540,7 @@ void llvm::omp::target::ompt::connectLibrary() {
547
540
FOREACH_OMPT_EMI_EVENT (bindOmptCallback)
548
541
#undef bindOmptCallback
549
542
550
- DP (" Exiting connectLibrary (libomp)\n " );
551
- }
552
-
553
- extern " C" {
554
- // / Used for connecting libomptarget with a plugin
555
- void ompt_libomptarget_connect (ompt_start_tool_result_t *result) {
556
- DP (" Enter ompt_libomptarget_connect\n " );
557
- if (CallbacksInitialized && result && LibraryFinalizer) {
558
- // Cache each fini function, so that they can be invoked on exit
559
- LibraryFinalizer->registerRtl (result->finalize );
560
- // Invoke the provided init function with the lookup function maintained
561
- // in this library so that callbacks maintained by this library are
562
- // retrieved.
563
- result->initialize (lookupCallbackByName,
564
- /* initial_device_num=*/ 0 , /* tool_data=*/ nullptr );
565
- }
566
- DP (" Leave ompt_libomptarget_connect\n " );
567
- }
543
+ DP (" Exiting connectLibrary\n " );
568
544
}
569
545
570
546
#pragma pop_macro("DEBUG_PREFIX")
0 commit comments