LLVM OpenMP 22.0.0git
InternalEventCommon.h
Go to the documentation of this file.
1//===- InternalEventCommon.h - Common internal event basics -----*- 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/// \file
10/// Provides event types, and class/operator declaration macros.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENTCOMMON_H
15#define OPENMP_TOOLS_OMPTEST_INCLUDE_INTERNALEVENTCOMMON_H
16
17#include "omp-tools.h"
18
19#include <cassert>
20#include <string>
21
22namespace omptest {
23
24namespace internal {
25/// Enum values are used for comparison of observed and asserted events
26/// List is based on OpenMP 5.2 specification, table 19.2 (page 447)
27enum class EventTy {
28 None, // not part of OpenMP spec, used for implementation
29 AssertionSyncPoint, // not part of OpenMP spec, used for implementation
30 AssertionSuspend, // not part of OpenMP spec, used for implementation
31 BufferRecord, // not part of OpenMP spec, used for implementation
32 BufferRecordDeallocation, // not part of OpenMP spec, used for implementation
37 Work,
39 TaskCreate, // TODO: Implement
40 Dependences, // TODO: Implement
41 TaskDependence, // TODO: Implement
42 TaskSchedule, // TODO: Implement
43 ImplicitTask, // TODO: Implement
44 Masked, // TODO: Implement
46 MutexAcquire, // TODO: Implement
47 Mutex, // TODO: Implement
48 NestLock, // TODO: Implement
49 Flush, // TODO: Implement
50 Cancel, // TODO: Implement
59 Target,
64};
65
66/// Base event class
67/// Offers default CTOR, DTOR and CTOR which assigns the actual event type.
71 virtual ~InternalEvent() = default;
72
73 virtual bool equals(const InternalEvent *o) const {
74 assert(false && "Base class implementation");
75 return false;
76 };
77
78 virtual std::string toString() const {
79 std::string S{"InternalEvent: Type="};
80 S.append(std::to_string((uint32_t)Type));
81 return S;
82 }
83
84 /// Identifying event type
86};
87
88/// Specialize EventType member for each derived internal event type.
89/// Effectively selecting an event type as initialization value.
90template <typename EventType> struct EventTypeOf;
91
92/// Actual definition macro for EventTypeOf.
93#define event_type_trait(EvTy) \
94 template <> struct EventTypeOf<EvTy> { \
95 static constexpr EventTy Value = EventTy::EvTy; \
96 };
97
98/// CRTP (Curiously Recurring Template Pattern) intermediate class
99/// Adding a new event type can be achieved by inheriting from an EventBase
100/// template instantiation of the new class' name, like this:
101/// struct NewEventType : public EventBase<NewEventType>
102template <typename Derived> class EventBase : public InternalEvent {
103public:
106 virtual ~EventBase() = default;
107
108 /// Equals method to cast and dispatch to the specific class operator==
109 virtual bool equals(const InternalEvent *o) const override {
110 // Note: When the if-condition evaluates to true, the event types are
111 // trivially identical. Otherwise, a cast to the Derived pointer would have
112 // been impossible.
113 if (const auto Other = dynamic_cast<const Derived *>(o))
114 return operator==(*static_cast<const Derived *>(this), *Other);
115 return false;
116 }
117
118 /// Basic toString method, which may be overridden with own implementations.
119 virtual std::string toString() const override {
120 std::string S{"EventBase: Type="};
121 S.append(std::to_string((uint32_t)Type));
122 return S;
123 }
124};
125
126} // namespace internal
127
128} // namespace omptest
129
130#endif
CRTP (Curiously Recurring Template Pattern) intermediate class Adding a new event type can be achieve...
virtual std::string toString() const override
Basic toString method, which may be overridden with own implementations.
virtual bool equals(const InternalEvent *o) const override
Equals method to cast and dispatch to the specific class operator==.
virtual ~EventBase()=default
static constexpr EventTy EventType
void const char const char int ITT_FORMAT __itt_group_sync x void const char ITT_FORMAT __itt_group_sync s void ITT_FORMAT __itt_group_sync p void ITT_FORMAT p void ITT_FORMAT p no args __itt_suppress_mode_t unsigned int void size_t ITT_FORMAT d void ITT_FORMAT p void ITT_FORMAT p __itt_model_site __itt_model_site_instance ITT_FORMAT p __itt_model_task __itt_model_task_instance ITT_FORMAT p void ITT_FORMAT p void ITT_FORMAT p void size_t ITT_FORMAT d void ITT_FORMAT p const wchar_t ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s const char ITT_FORMAT s no args void ITT_FORMAT p size_t ITT_FORMAT d no args const wchar_t const wchar_t ITT_FORMAT s __itt_heap_function void size_t int ITT_FORMAT d __itt_heap_function void ITT_FORMAT p __itt_heap_function void void size_t int ITT_FORMAT d no args no args unsigned int ITT_FORMAT u const __itt_domain __itt_id ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain __itt_id ITT_FORMAT p const __itt_domain __itt_id __itt_timestamp __itt_timestamp ITT_FORMAT lu const __itt_domain __itt_id __itt_id __itt_string_handle ITT_FORMAT p const __itt_domain ITT_FORMAT p const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_string_handle unsigned long long ITT_FORMAT lu const __itt_domain __itt_id __itt_string_handle __itt_metadata_type size_t void ITT_FORMAT p const __itt_domain __itt_id __itt_string_handle const wchar_t size_t ITT_FORMAT lu const __itt_domain __itt_id __itt_relation __itt_id ITT_FORMAT p const wchar_t int ITT_FORMAT __itt_group_mark S
bool operator==(const ParallelBegin &, const ParallelBegin &)
EventTy
Enum values are used for comparison of observed and asserted events List is based on OpenMP 5....
Specialize EventType member for each derived internal event type.
Base event class Offers default CTOR, DTOR and CTOR which assigns the actual event type.
EventTy Type
Identifying event type.
virtual bool equals(const InternalEvent *o) const
virtual ~InternalEvent()=default
virtual std::string toString() const